Commit 7275013e authored by harrylee's avatar harrylee Committed by vipwzw

update accountmanager

parent 814d6a11
package executor
import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"time"
et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
"github.com/stretchr/testify/assert"
"testing"
)
type execEnv struct {
blockTime int64
blockHeight int64
difficulty uint64
}
var (
PrivKeyA = "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" // 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
PrivKeyB = "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" // 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
PrivKeyC = "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" // 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k
PrivKeyD = "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71" // 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs
Nodes = []string{
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4",
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR",
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k",
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs",
}
)
func TestAccountManager(t *testing.T) {
//环境准备
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
Init(et.AccountmanagerX, cfg, nil)
total := 100 * types.Coin
accountA := types.Account{
Balance: total,
Frozen: 0,
Addr: Nodes[0],
}
accountB := types.Account{
Balance: total,
Frozen: 0,
Addr: Nodes[1],
}
accountC := types.Account{
Balance: total,
Frozen: 0,
Addr: Nodes[2],
}
accountD := types.Account{
Balance: total,
Frozen: 0,
Addr: Nodes[3],
}
_, stateDB, kvdb := util.CreateTestDB()
//defer util.CloseTestDB(dir, stateDB)
execAddr := address.ExecAddress(et.AccountmanagerX)
accA, _ := account.NewAccountDB(cfg, "coins", "bty", stateDB)
accA.SaveExecAccount(execAddr, &accountA)
accB, _ := account.NewAccountDB(cfg, "coins", "bty", stateDB)
accB.SaveExecAccount(execAddr, &accountB)
accC, _ := account.NewAccountDB(cfg, "coins", "bty", stateDB)
accC.SaveExecAccount(execAddr, &accountC)
accD, _ := account.NewAccountDB(cfg, "coins", "bty", stateDB)
accD.SaveExecAccount(execAddr, &accountD)
env := &execEnv{
time.Now().Unix(),
1,
1539918074,
}
// set config key
item := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameActiveTime,
Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{"10"}},
},
}
stateDB.Set([]byte(item.Key), types.Encode(item))
item2 := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameManagerAddr,
Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{string(Nodes[0])}},
},
}
stateDB.Set([]byte(item2.Key), types.Encode(item2))
item3 := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameLockTime,
Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{"15"}},
},
}
stateDB.Set([]byte(item3.Key), types.Encode(item3))
//注册
tx1,err := CreateRegister(&et.Register{AccountID:"harrylee2015"},PrivKeyB)
if err !=nil {
t.Error(err)
}
Exec_Block(t,stateDB,kvdb,env,tx1)
tx2,err := CreateRegister(&et.Register{AccountID:"harrylee2015"},PrivKeyC)
err=Exec_Block(t,stateDB,kvdb,env,tx2)
assert.Equal(t,err,et.ErrAccountIDExist)
tx3,err := CreateRegister(&et.Register{AccountID:"harrylee2020"},PrivKeyC)
Exec_Block(t,stateDB,kvdb,env,tx3)
tx4,err:=CreateTransfer(&et.Transfer{FromAccountID:"harrylee2015",ToAccountID:"harrylee2020",Amount:1e8,Asset:&et.Asset{Execer:"coins",Symbol:"bty"}},PrivKeyB)
if err !=nil {
t.Error(err)
}
err=Exec_Block(t,stateDB,kvdb,env,tx4)
assert.Equal(t,err,nil)
}
func CreateRegister(register *et.Register, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameRegisterAction, register)
if err != nil {
return nil, err
}
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
tx, err = types.FormatTx(cfg, et.AccountmanagerX, tx)
if err != nil {
return nil, err
}
tx, err = signTx(tx, privKey)
if err != nil {
return nil, err
}
return tx, nil
}
func CreateReset(reset *et.ResetKey, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameResetAction, reset)
if err != nil {
return nil, err
}
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
tx, err = types.FormatTx(cfg, et.AccountmanagerX, tx)
if err != nil {
return nil, err
}
tx, err = signTx(tx, privKey)
if err != nil {
return nil, err
}
return tx, nil
}
func CreateTransfer(tranfer *et.Transfer, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameTransferAction, tranfer)
if err != nil {
return nil, err
}
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
tx, err = types.FormatTx(cfg, et.AccountmanagerX, tx)
if err != nil {
return nil, err
}
tx, err = signTx(tx, privKey)
if err != nil {
return nil, err
}
return tx, nil
}
func CreateSupervise(supervise *et.Supervise, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameSuperviseAction, supervise)
if err != nil {
return nil, err
}
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
tx, err = types.FormatTx(cfg, et.AccountmanagerX, tx)
if err != nil {
return nil, err
}
tx, err = signTx(tx, privKey)
if err != nil {
return nil, err
}
return tx, nil
}
func CreateApply(apply *et.Apply, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameSuperviseAction, apply)
if err != nil {
return nil, err
}
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
tx, err = types.FormatTx(cfg, et.AccountmanagerX, tx)
if err != nil {
return nil, err
}
tx, err = signTx(tx, privKey)
if err != nil {
return nil, err
}
return tx, nil
}
//模拟区块中交易得执行过程
func Exec_Block(t *testing.T, stateDB db.DB, kvdb db.KVDB, env *execEnv, txs ...*types.Transaction) error {
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
exec := newAccountmanager()
e := exec.(*accountmanager)
for index, tx := range txs {
err := e.CheckTx(tx, index)
if err != nil {
return err
}
}
q := queue.New("channel")
q.SetConfig(cfg)
api, _ := client.New(q.Client(), nil)
exec.SetAPI(api)
exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb)
env.blockHeight = env.blockHeight + 1
env.blockTime = env.blockTime + 1
env.difficulty = env.difficulty + 1
exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty)
for index, tx := range txs {
receipt, err := exec.Exec(tx, index)
if err != nil {
return err
}
for _, kv := range receipt.KV {
stateDB.Set(kv.Key, kv.Value)
}
receiptData := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err := exec.ExecLocal(tx, receiptData, index)
if err != nil {
return err
}
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
//save to database
util.SaveKVList(stateDB, set.KV)
assert.Equal(t, types.ExecOk, int(receipt.Ty))
}
return nil
}
func Exec_QueryAccountByID(accountID string, stateDB db.KV, kvdb db.KVDB) (*et.Account, error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
exec := newAccountmanager()
q := queue.New("channel")
q.SetConfig(cfg)
api, _ := client.New(q.Client(), nil)
exec.SetAPI(api)
exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb)
msg, err := exec.Query(et.FuncNameQueryAccountByID, types.Encode(&et.QueryAccountByID{AccountID: accountID}))
if err != nil {
return nil, err
}
return msg.(*et.Account), err
}
func Exec_QueryAccountsByStatus(status int32, stateDB db.KV, kvdb db.KVDB) (*et.ReplyAccountList, error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
exec := newAccountmanager()
q := queue.New("channel")
q.SetConfig(cfg)
api, _ := client.New(q.Client(), nil)
exec.SetAPI(api)
exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb)
msg, err := exec.Query(et.FuncNameQueryAccountsByStatus, types.Encode(&et.QueryAccountsByStatus{Status:status}))
if err != nil {
return nil, err
}
return msg.(*et.ReplyAccountList), err
}
func Exec_QueryExpiredAccounts(status int32, stateDB db.KV, kvdb db.KVDB) (*et.ReplyAccountList, error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
exec := newAccountmanager()
q := queue.New("channel")
q.SetConfig(cfg)
api, _ := client.New(q.Client(), nil)
exec.SetAPI(api)
exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb)
msg, err := exec.Query(et.FuncNameQueryExpiredAccounts, types.Encode(&et.QueryExpiredAccounts{}))
if err != nil {
return nil, err
}
return msg.(*et.ReplyAccountList), err
}
func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) {
signType := types.SECP256K1
c, err := crypto.New(types.GetSignName("", signType))
if err != nil {
return tx, err
}
bytes, err := common.FromHex(hexPrivKey[:])
if err != nil {
return tx, err
}
privKey, err := c.PrivKeyFromBytes(bytes)
if err != nil {
return tx, err
}
tx.Sign(int32(signType), privKey)
return tx, nil
}
...@@ -51,6 +51,11 @@ func (a *accountmanager) GetDriverName() string { ...@@ -51,6 +51,11 @@ func (a *accountmanager) GetDriverName() string {
return driverName return driverName
} }
//ExecutorOrder Exec 的时候 同时执行 ExecLocal
func (e *accountmanager) ExecutorOrder() int64 {
return drivers.ExecLocalSameTime
}
// CheckTx 实现自定义检验交易接口,供框架调用 // CheckTx 实现自定义检验交易接口,供框架调用
func (a *accountmanager) CheckTx(tx *types.Transaction, index int) error { func (a *accountmanager) CheckTx(tx *types.Transaction, index int) error {
// implement code // implement code
......
...@@ -11,32 +11,25 @@ import ( ...@@ -11,32 +11,25 @@ import (
*/ */
func (a *accountmanager) Exec_Register(payload *aty.Register, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_Register(payload *aty.Register, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt action := NewAction(a, tx, index)
//implement code return action.Register(payload)
return receipt, nil
} }
func (a *accountmanager) Exec_Reset(payload *aty.Reset, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_Resetkey(payload *aty.ResetKey, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt action := NewAction(a, tx, index)
//implement code return action.Reset(payload)
return receipt, nil
} }
func (a *accountmanager) Exec_Transfer(payload *aty.Transfer, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_Transfer(payload *aty.Transfer, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt action := NewAction(a, tx, index)
//implement code return action.Transfer(payload)
return receipt, nil
} }
func (a *accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt action := NewAction(a, tx, index)
//implement code return action.Supervise(payload)
return receipt, nil
} }
func (a *accountmanager) ExecApply(payload *aty.Apply, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_Apply(payload *aty.Apply, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt return nil, types.ErrActionNotSupport
//implement code }
return receipt, nil
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ package executor ...@@ -2,7 +2,7 @@ package executor
import ( import (
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
accountmanagertypes "github.com/33cn/plugin/plugin/dapp/accountmanager/types" et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
) )
/* /*
...@@ -10,38 +10,127 @@ import ( ...@@ -10,38 +10,127 @@ import (
* 非关键数据,本地存储(localDB), 用于辅助查询,效率高 * 非关键数据,本地存储(localDB), 用于辅助查询,效率高
*/ */
func (a *accountmanager) ExecLocal_Register(payload *accountmanagertypes.Register, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (a *accountmanager) ExecLocal_Register(payload *et.Register, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code if receiptData.Ty == types.ExecOk {
for _, log := range receiptData.Logs {
switch log.Ty {
case et.TyRegisterLog:
receipt := &et.AccountReceipt{}
if err := types.Decode(log.Log, receipt); err != nil {
return nil, err
}
accountTable := NewAccountTable(a.GetLocalDB())
err := accountTable.Add(receipt.Account)
if err != nil {
return nil, err
}
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
}
}
}
return a.addAutoRollBack(tx, dbSet.KV), nil return a.addAutoRollBack(tx, dbSet.KV), nil
} }
func (a *accountmanager) ExecLocal_Reset(payload *accountmanagertypes.Reset, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (a *accountmanager) ExecLocal_ResetKey(payload *et.ResetKey, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code if receiptData.Ty == types.ExecOk {
for _, log := range receiptData.Logs {
switch log.Ty {
case et.TyResetLog:
receipt := &et.AccountReceipt{}
if err := types.Decode(log.Log, receipt); err != nil {
return nil, err
}
accountTable := NewAccountTable(a.GetLocalDB())
err := accountTable.Replace(receipt.Account)
if err != nil {
return nil, err
}
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
}
}
}
return a.addAutoRollBack(tx, dbSet.KV), nil return a.addAutoRollBack(tx, dbSet.KV), nil
} }
func (a *accountmanager) ExecLocal_Apply(payload *accountmanagertypes.Apply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (a *accountmanager) ExecLocal_Apply(payload *et.Apply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code if receiptData.Ty == types.ExecOk {
for _, log := range receiptData.Logs {
switch log.Ty {
case et.TyApplyLog:
receipt := &et.AccountReceipt{}
if err := types.Decode(log.Log, receipt); err != nil {
return nil, err
}
accountTable := NewAccountTable(a.GetLocalDB())
err := accountTable.Replace(receipt.Account)
if err != nil {
return nil, err
}
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
}
}
}
return a.addAutoRollBack(tx, dbSet.KV), nil return a.addAutoRollBack(tx, dbSet.KV), nil
} }
func (a *accountmanager) ExecLocal_Transfer(payload *accountmanagertypes.Transfer, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (a *accountmanager) ExecLocal_Transfer(payload *et.Transfer, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code if receiptData.Ty == types.ExecOk {
for _, log := range receiptData.Logs {
switch log.Ty {
case et.TyResetLog:
//账户信息不变更,不需要处理
}
}
}
return a.addAutoRollBack(tx, dbSet.KV), nil return a.addAutoRollBack(tx, dbSet.KV), nil
} }
func (a *accountmanager) ExecLocal_Supervise(payload *accountmanagertypes.Supervise, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (a *accountmanager) ExecLocal_Supervise(payload *et.Supervise, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code if receiptData.Ty == types.ExecOk {
for _, log := range receiptData.Logs {
switch log.Ty {
case et.TySuperviseLog:
receipt := &et.SuperviseReceipt{}
if err := types.Decode(log.Log, receipt); err != nil {
return nil, err
}
accountTable := NewAccountTable(a.GetLocalDB())
for _, account := range receipt.Accounts {
err := accountTable.Replace(account)
if err != nil {
return nil, err
}
}
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
}
}
}
return a.addAutoRollBack(tx, dbSet.KV), nil return a.addAutoRollBack(tx, dbSet.KV), nil
} }
//设置自动回滚 //设置自动回滚
func (a *accountmanager) addAutoRollBack(tx *types.Transaction, kv []*types.KeyValue) *types.LocalDBSet { func (a *accountmanager) addAutoRollBack(tx *types.Transaction, kv []*types.KeyValue) *types.LocalDBSet {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
dbSet.KV = a.AddRollbackKV(tx, tx.Execer, kv) dbSet.KV = a.AddRollbackKV(tx, tx.Execer, kv)
return dbSet return dbSet
......
package executor
import (
"github.com/33cn/chain33/types"
et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
//根据ID查询账户信息
func (s *accountmanager) Query_QueryAccountByID(in *et.QueryAccountByID) (types.Message, error) {
return findAccountByID(s.GetLocalDB(), in.AccountID)
}
//根据状态查询账户列表|| 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
func (s *accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatus) (types.Message, error) {
return findAccountListByStatus(s.GetLocalDB(), in.Status, in.Direction, in.PrimaryKey)
}
//查询逾期注销的账户列表
func (s *accountmanager) Query_QueryExpiredAccounts(in *et.QueryExpiredAccounts) (types.Message, error) {
return findAccountListByIndex(s.GetLocalDB(), in.Direction, in.PrimaryKey)
}
...@@ -24,13 +24,13 @@ const ( ...@@ -24,13 +24,13 @@ const (
var opt_account = &table.Option{ var opt_account = &table.Option{
Prefix: KeyPrefixLocalDB, Prefix: KeyPrefixLocalDB,
Name: "account", Name: "account",
Primary: "accountName", Primary: "index",
Index: []string{"status"}, Index: []string{"status", "accountID"},
} }
//状态数据库中存储具体账户信息 //状态数据库中存储具体账户信息
func calcAccountKey(accountName string) []byte { func calcAccountKey(accountID string) []byte {
key := fmt.Sprintf("%s"+"accountName:%s", KeyPrefixStateDB, accountName) key := fmt.Sprintf("%s"+"accountID:%s", KeyPrefixStateDB, accountID)
return []byte(key) return []byte(key)
} }
...@@ -73,6 +73,8 @@ func (m *AccountRow) Get(key string) ([]byte, error) { ...@@ -73,6 +73,8 @@ func (m *AccountRow) Get(key string) ([]byte, error) {
return []byte(fmt.Sprintf("%s", m.AccountID)), nil return []byte(fmt.Sprintf("%s", m.AccountID)), nil
} else if key == "status" { } else if key == "status" {
return []byte(fmt.Sprintf("%d", m.Status)), nil return []byte(fmt.Sprintf("%d", m.Status)), nil
} else if key == "index" {
return []byte(fmt.Sprintf("%014d", m.GetIndex())), nil
} }
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
...@@ -5,6 +5,6 @@ import ( ...@@ -5,6 +5,6 @@ import (
"testing" "testing"
) )
func Test(t *testing.T){ func Test(t *testing.T) {
t.Log(fmt.Sprintf("%-s","aaaa100000b")) t.Log(fmt.Sprintf("%-s", "aaaa100000b"))
} }
\ No newline at end of file
...@@ -9,7 +9,7 @@ message AccountmanagerAction { ...@@ -9,7 +9,7 @@ message AccountmanagerAction {
//注册 //注册
Register register = 1; Register register = 1;
//重置公钥 //重置公钥
Reset reset = 2; ResetKey resetKey = 2;
//转账 //转账
Transfer transfer = 3; Transfer transfer = 3;
//监管操作 //监管操作
...@@ -28,7 +28,8 @@ message Register { ...@@ -28,7 +28,8 @@ message Register {
} }
//重置公钥 //重置公钥
message Reset { message ResetKey {
string accountID = 1; string accountID = 1;
string addr = 2; string addr = 2;
} }
...@@ -36,7 +37,7 @@ message Reset { ...@@ -36,7 +37,7 @@ message Reset {
//用户申请服务 //用户申请服务
message Apply { message Apply {
string accountID = 1; string accountID = 1;
//操作, 0,账户注册,1,账户公钥重置 2,账户延期申请 3,账户注销 //操作, 1 撤销账户公钥重置, 2 锁定期结束后,执行重置公钥操作
int32 op = 2; int32 op = 2;
} }
...@@ -63,11 +64,11 @@ message Transfer { ...@@ -63,11 +64,11 @@ message Transfer {
message Supervise { message Supervise {
//账户名单 //账户名单
repeated string accountIDs = 1; repeated string accountIDs = 1;
//操作, 1为冻结,2为解冻 //操作, 1为冻结,2为解冻,3增加有效期
int32 op = 2; int32 op = 2;
} }
message Account{ message account{
//账户名称 //账户名称
string accountID = 1; string accountID = 1;
//地址 //地址
...@@ -86,23 +87,47 @@ message Account{ ...@@ -86,23 +87,47 @@ message Account{
int64 index = 8; int64 index = 8;
} }
message Receipt{ message AccountReceipt{
//账户名称 account account = 1;
}
message ReplyAccountList {
repeated account accounts = 1;
string primaryKey = 2;
}
message TransferReceipt{
account FromAccount = 1;
account ToAccount = 2;
int64 blockTime = 3;
}
//回执日志
message SuperviseReceipt{
repeated account accounts = 1;
int32 op = 2;
int64 blockTime = 3;
}
message QueryExpiredAccounts{
string primaryKey = 1;
//单页返回多少条记录,默认返回10条
// 0降序,1升序,默认降序
int32 direction = 2;
}
message QueryAccountsByStatus{
//账户状态 1 正常, 2表示冻结, 3表示锁定
int32 status = 1;
// 主键索引
string primaryKey = 3;
// 0降序,1升序,默认降序
int32 direction = 5;
}
message QueryAccountByID {
string accountID = 1; string accountID = 1;
//地址
string addr = 2;
//上一次公钥地址
string prevAddr = 3;
//账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
int32 status = 4;
//注册时间
int64 createTime = 5;
//失效时间
int64 expireTime = 6;
//锁定时间
int64 lockTime = 7;
//索引
int64 index = 8;
} }
service accountmanager { service accountmanager {
......
...@@ -3,6 +3,7 @@ package types ...@@ -3,6 +3,7 @@ package types
import ( import (
log "github.com/33cn/chain33/common/log/log15" log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
"reflect"
) )
/* /*
...@@ -21,30 +22,59 @@ const ( ...@@ -21,30 +22,59 @@ const (
TyApplyAction TyApplyAction
NameRegisterAction = "Register" NameRegisterAction = "Register"
NameResetAction = "Reset" NameResetAction = "ResetKey"
NameTransferAction = "Transfer" NameTransferAction = "Transfer"
NameSuperviseAction = "Supervise" NameSuperviseAction = "Supervise"
NameApplyAction = "Apply" NameApplyAction = "Apply"
FuncNameQueryAccountByID = "QueryAccountByID"
FuncNameQueryAccountsByStatus = "QueryAccountsByStatus"
FuncNameQueryExpiredAccounts = "QueryExpiredAccounts"
) )
// log类型id值 // log类型id值
const ( const (
TyUnknownLog = iota + 100 TyUnknownLog = iota + 100
TyRegisterLog TyRegisterLog
TyApplyLog TyResetLog
TyTransferLog TyTransferLog
TySuperviseLog TySuperviseLog
TyApplyLog
) )
//状态 //状态
const ( const (
UnknownStatus = iota UnknownStatus = int32(iota)
Normal Normal
Frozen Frozen
Locked Locked
Expired Expired
) )
//supervior op
const (
UnknownSupervisorOp = int32(iota)
Freeze
UnFreeze
AddExpire
)
//apply op
const (
UnknownApplyOp = int32(iota)
RevokeReset
EnforceReset
)
const (
ListDESC = int32(0)
ListASC = int32(1)
ListSeek = int32(2)
)
const (
//单次list还回条数
Count = int32(10)
)
var ( var (
//AccountmanagerX 执行器名称定义 //AccountmanagerX 执行器名称定义
AccountmanagerX = "accountmanager" AccountmanagerX = "accountmanager"
...@@ -58,7 +88,11 @@ var ( ...@@ -58,7 +88,11 @@ var (
} }
//定义log的id和具体log类型及名称,填入具体自定义log类型 //定义log的id和具体log类型及名称,填入具体自定义log类型
logMap = map[int64]*types.LogInfo{ logMap = map[int64]*types.LogInfo{
//LogID: {Ty: reflect.TypeOf(LogStruct), Name: LogName}, TyRegisterLog: {Ty: reflect.TypeOf(AccountReceipt{}), Name: "TyRegisterLog"},
TyResetLog: {Ty: reflect.TypeOf(TransferReceipt{}), Name: "TyResetLog"},
TyTransferLog: {Ty: reflect.TypeOf(AccountReceipt{}), Name: "TyTransferLog"},
TySuperviseLog: {Ty: reflect.TypeOf(SuperviseReceipt{}), Name: "TySuperviseLog"},
TyApplyLog: {Ty: reflect.TypeOf(AccountReceipt{}), Name: "TyApplyLog"},
} }
tlog = log.New("module", "accountmanager.types") tlog = log.New("module", "accountmanager.types")
) )
......
...@@ -4,7 +4,9 @@ import "fmt" ...@@ -4,7 +4,9 @@ import "fmt"
// some errors definition // some errors definition
var ( var (
ErrAccountNameExist = fmt.Errorf("%s", "The account name has been registered!") ErrAccountIDExist = fmt.Errorf("%s", "The account ID has been registered!")
ErrAccountNameNotExist = fmt.Errorf("%s", "The account name is not exist") ErrAccountIDNotExist = fmt.Errorf("%s", "The account ID is not exist")
ErrAccountIDNotPermiss = fmt.Errorf("%s", "You don't have permission to do that!")
ErrAssetBalance = fmt.Errorf("%s", "Insufficient balance!")
ErrNotAdmin = fmt.Errorf("%s", "No adiministrator privileges!")
) )
package init package init
import ( import (
_ "github.com/33cn/plugin/plugin/dapp/autonomy" //auto gen _ "github.com/33cn/plugin/plugin/dapp/accountmanager" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/blackwhite" //auto gen _ "github.com/33cn/plugin/plugin/dapp/autonomy" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/cert" //auto gen _ "github.com/33cn/plugin/plugin/dapp/blackwhite" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/collateralize" //auto gen _ "github.com/33cn/plugin/plugin/dapp/cert" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/dposvote" //auto gen _ "github.com/33cn/plugin/plugin/dapp/collateralize" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/echo" //auto gen _ "github.com/33cn/plugin/plugin/dapp/dposvote" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/evm" //auto gen _ "github.com/33cn/plugin/plugin/dapp/echo" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/exchange" //auto gen _ "github.com/33cn/plugin/plugin/dapp/evm" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/game" //auto gen _ "github.com/33cn/plugin/plugin/dapp/exchange" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/guess" //auto gen _ "github.com/33cn/plugin/plugin/dapp/game" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/hashlock" //auto gen _ "github.com/33cn/plugin/plugin/dapp/guess" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/issuance" //auto gen _ "github.com/33cn/plugin/plugin/dapp/hashlock" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/js" //auto gen _ "github.com/33cn/plugin/plugin/dapp/issuance" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen _ "github.com/33cn/plugin/plugin/dapp/js" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen _ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen _ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/oracle" //auto gen _ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen _ "github.com/33cn/plugin/plugin/dapp/oracle" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen _ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/privacy" //auto gen _ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/relay" //auto gen _ "github.com/33cn/plugin/plugin/dapp/privacy" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/retrieve" //auto gen _ "github.com/33cn/plugin/plugin/dapp/relay" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/storage" //auto gen _ "github.com/33cn/plugin/plugin/dapp/retrieve" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/ticket" //auto gen _ "github.com/33cn/plugin/plugin/dapp/storage" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/token" //auto gen _ "github.com/33cn/plugin/plugin/dapp/ticket" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/trade" //auto gen _ "github.com/33cn/plugin/plugin/dapp/token" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/unfreeze" //auto gen _ "github.com/33cn/plugin/plugin/dapp/trade" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/valnode" //auto gen _ "github.com/33cn/plugin/plugin/dapp/unfreeze" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/valnode" //auto gen
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment