Commit c7dfe374 authored by harrylee's avatar harrylee Committed by vipwzw

update accountmanager

parent 7275013e
...@@ -85,7 +85,7 @@ func TestAccountManager(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestAccountManager(t *testing.T) {
} }
// set config key // set config key
item := &types.ConfigItem{ item := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameActiveTime, Key: "mavl-manage-" + ConfNameActiveTime,
Value: &types.ConfigItem_Arr{ Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{"10"}}, Arr: &types.ArrayConfig{Value: []string{"10"}},
}, },
...@@ -93,7 +93,7 @@ func TestAccountManager(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestAccountManager(t *testing.T) {
stateDB.Set([]byte(item.Key), types.Encode(item)) stateDB.Set([]byte(item.Key), types.Encode(item))
item2 := &types.ConfigItem{ item2 := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameManagerAddr, Key: "mavl-manage-" + ConfNameManagerAddr,
Value: &types.ConfigItem_Arr{ Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{string(Nodes[0])}}, Arr: &types.ArrayConfig{Value: []string{string(Nodes[0])}},
}, },
...@@ -101,31 +101,92 @@ func TestAccountManager(t *testing.T) { ...@@ -101,31 +101,92 @@ func TestAccountManager(t *testing.T) {
stateDB.Set([]byte(item2.Key), types.Encode(item2)) stateDB.Set([]byte(item2.Key), types.Encode(item2))
item3 := &types.ConfigItem{ item3 := &types.ConfigItem{
Key: "mavl-manage-"+ConfNameLockTime, Key: "mavl-manage-" + ConfNameLockTime,
Value: &types.ConfigItem_Arr{ Value: &types.ConfigItem_Arr{
Arr: &types.ArrayConfig{Value: []string{"15"}}, Arr: &types.ArrayConfig{Value: []string{"2"}},
}, },
} }
stateDB.Set([]byte(item3.Key), types.Encode(item3)) stateDB.Set([]byte(item3.Key), types.Encode(item3))
//注册 //注册
tx1,err := CreateRegister(&et.Register{AccountID:"harrylee2015"},PrivKeyB) tx1, err := CreateRegister(&et.Register{AccountID: "harrylee2015"}, PrivKeyB)
if err !=nil { if err != nil {
t.Error(err) t.Error(err)
} }
Exec_Block(t,stateDB,kvdb,env,tx1) Exec_Block(t, stateDB, kvdb, env, tx1)
tx2,err := CreateRegister(&et.Register{AccountID:"harrylee2015"},PrivKeyC) tx2, err := CreateRegister(&et.Register{AccountID: "harrylee2015"}, PrivKeyC)
err=Exec_Block(t,stateDB,kvdb,env,tx2) err = Exec_Block(t, stateDB, kvdb, env, tx2)
assert.Equal(t,err,et.ErrAccountIDExist) assert.Equal(t, err, et.ErrAccountIDExist)
tx3,err := CreateRegister(&et.Register{AccountID:"harrylee2020"},PrivKeyC) tx3, err := CreateRegister(&et.Register{AccountID: "harrylee2020"}, PrivKeyC)
Exec_Block(t,stateDB,kvdb,env,tx3) 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)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx4)
assert.Equal(t, err, nil)
//重置公钥
tx5, err := CreateReset(&et.ResetKey{Addr: "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs", AccountID: "harrylee2015"}, PrivKeyA)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx5)
//在锁定期内撤回请求
tx6, err := CreateApply(&et.Apply{Op: et.RevokeReset, AccountID: "harrylee2015"}, PrivKeyB)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx6)
assert.Equal(t, err, nil)
//重置公钥
tx5, err = CreateReset(&et.ResetKey{Addr: "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs", AccountID: "harrylee2015"}, PrivKeyA)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx5)
time.Sleep(time.Second)
//过了锁定期,申请生效
tx6, err = CreateApply(&et.Apply{Op: et.EnforceReset, AccountID: "harrylee2015"}, PrivKeyD)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx6)
tx7, _ := CreateTransfer(&et.Transfer{FromAccountID: "harrylee2015", ToAccountID: "harrylee2015", Amount: 1e8, Asset: &et.Asset{Execer: "coins", Symbol: "bty"}}, PrivKeyD)
err = Exec_Block(t, stateDB, kvdb, env, tx7)
assert.Equal(t, err, nil)
balance, err := Exec_QueryBalanceByID(&et.QueryBalanceByID{AccountID: "harrylee2015", Asset: &et.Asset{Symbol: "bty", Execer: "coins"}}, stateDB, kvdb)
assert.Equal(t, err, nil)
assert.Equal(t, balance.Balance, 199*types.Coin)
//将某个账户冻结
tx8, _ := CreateSupervise(&et.Supervise{
AccountIDs: []string{"harrylee2015"},
Op: et.Freeze,
}, PrivKeyA)
err = Exec_Block(t, stateDB, kvdb, env, tx8)
assert.Equal(t, err, nil)
//根据状态查询
accounts, err := Exec_QueryAccountsByStatus(et.Frozen, stateDB, kvdb)
assert.Equal(t, err, nil)
assert.Equal(t, accounts.Accounts[0].Status, et.Frozen)
balance, err = Exec_QueryBalanceByID(&et.QueryBalanceByID{Asset: &et.Asset{Execer: "coins", Symbol: "bty"}, AccountID: "harrylee2015"}, stateDB, kvdb)
assert.Equal(t, err, nil)
assert.Equal(t, balance.Frozen, 199*types.Coin)
tx4,err:=CreateTransfer(&et.Transfer{FromAccountID:"harrylee2015",ToAccountID:"harrylee2020",Amount:1e8,Asset:&et.Asset{Execer:"coins",Symbol:"bty"}},PrivKeyB) //解冻账户
if err !=nil { tx9, _ := CreateSupervise(&et.Supervise{
AccountIDs: []string{"harrylee2015"},
Op: et.UnFreeze,
}, PrivKeyA)
err = Exec_Block(t, stateDB, kvdb, env, tx9)
assert.Equal(t, err, nil)
//根据状态查询
accounts, err = Exec_QueryAccountsByStatus(et.Frozen, stateDB, kvdb)
assert.NotEqual(t, err, nil)
balance, err = Exec_QueryBalanceByID(&et.QueryBalanceByID{Asset: &et.Asset{Execer: "coins", Symbol: "bty"}, AccountID: "harrylee2015"}, stateDB, kvdb)
assert.Equal(t, err, nil)
assert.Equal(t, balance.Balance, 199*types.Coin)
//过期账户查询
time.Sleep(10 * time.Second)
t.Log(time.Now().Unix())
accs, err := Exec_QueryExpiredAccounts(time.Now().Unix(), stateDB, kvdb)
if err != nil {
t.Error(err) t.Error(err)
} }
err=Exec_Block(t,stateDB,kvdb,env,tx4) t.Log(accs)
assert.Equal(t,err,nil)
} }
func CreateRegister(register *et.Register, privKey string) (tx *types.Transaction, err error) { func CreateRegister(register *et.Register, privKey string) (tx *types.Transaction, err error) {
...@@ -206,7 +267,7 @@ func CreateSupervise(supervise *et.Supervise, privKey string) (tx *types.Transac ...@@ -206,7 +267,7 @@ func CreateSupervise(supervise *et.Supervise, privKey string) (tx *types.Transac
func CreateApply(apply *et.Apply, privKey string) (tx *types.Transaction, err error) { func CreateApply(apply *et.Apply, privKey string) (tx *types.Transaction, err error) {
ety := types.LoadExecutorType(et.AccountmanagerX) ety := types.LoadExecutorType(et.AccountmanagerX)
tx, err = ety.Create(et.NameSuperviseAction, apply) tx, err = ety.Create(et.NameApplyAction, apply)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -222,6 +283,7 @@ func CreateApply(apply *et.Apply, privKey string) (tx *types.Transaction, err er ...@@ -222,6 +283,7 @@ func CreateApply(apply *et.Apply, privKey string) (tx *types.Transaction, err er
} }
return tx, nil return tx, nil
} }
//模拟区块中交易得执行过程 //模拟区块中交易得执行过程
func Exec_Block(t *testing.T, stateDB db.DB, kvdb db.KVDB, env *execEnv, txs ...*types.Transaction) error { func Exec_Block(t *testing.T, stateDB db.DB, kvdb db.KVDB, env *execEnv, txs ...*types.Transaction) error {
cfg := types.NewChain33Config(types.GetDefaultCfgstring()) cfg := types.NewChain33Config(types.GetDefaultCfgstring())
...@@ -285,6 +347,22 @@ func Exec_QueryAccountByID(accountID string, stateDB db.KV, kvdb db.KVDB) (*et.A ...@@ -285,6 +347,22 @@ func Exec_QueryAccountByID(accountID string, stateDB db.KV, kvdb db.KVDB) (*et.A
return msg.(*et.Account), err return msg.(*et.Account), err
} }
func Exec_QueryAccountByAddr(addr 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.FuncNameQueryAccountByAddr, types.Encode(&et.QueryAccountByAddr{Addr: addr}))
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) { func Exec_QueryAccountsByStatus(status int32, stateDB db.KV, kvdb db.KVDB) (*et.ReplyAccountList, error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring()) cfg := types.NewChain33Config(types.GetDefaultCfgstring())
...@@ -296,14 +374,14 @@ func Exec_QueryAccountsByStatus(status int32, stateDB db.KV, kvdb db.KVDB) (*et. ...@@ -296,14 +374,14 @@ func Exec_QueryAccountsByStatus(status int32, stateDB db.KV, kvdb db.KVDB) (*et.
exec.SetAPI(api) exec.SetAPI(api)
exec.SetStateDB(stateDB) exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb) exec.SetLocalDB(kvdb)
msg, err := exec.Query(et.FuncNameQueryAccountsByStatus, types.Encode(&et.QueryAccountsByStatus{Status:status})) msg, err := exec.Query(et.FuncNameQueryAccountsByStatus, types.Encode(&et.QueryAccountsByStatus{Status: status}))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return msg.(*et.ReplyAccountList), err return msg.(*et.ReplyAccountList), err
} }
func Exec_QueryExpiredAccounts(status int32, stateDB db.KV, kvdb db.KVDB) (*et.ReplyAccountList, error) { func Exec_QueryBalanceByID(in *et.QueryBalanceByID, stateDB db.KV, kvdb db.KVDB) (*et.Balance, error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring()) cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33") cfg.SetTitleOnlyForTest("chain33")
exec := newAccountmanager() exec := newAccountmanager()
...@@ -313,14 +391,29 @@ func Exec_QueryExpiredAccounts(status int32, stateDB db.KV, kvdb db.KVDB) (*et.R ...@@ -313,14 +391,29 @@ func Exec_QueryExpiredAccounts(status int32, stateDB db.KV, kvdb db.KVDB) (*et.R
exec.SetAPI(api) exec.SetAPI(api)
exec.SetStateDB(stateDB) exec.SetStateDB(stateDB)
exec.SetLocalDB(kvdb) exec.SetLocalDB(kvdb)
msg, err := exec.Query(et.FuncNameQueryExpiredAccounts, types.Encode(&et.QueryExpiredAccounts{})) msg, err := exec.Query(et.FuncNameQueryBalanceByID, types.Encode(in))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return msg.(*et.ReplyAccountList), err return msg.(*et.Balance), err
} }
func Exec_QueryExpiredAccounts(expiredtime int64, 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{ExpiredTime: expiredtime, Direction: 0}))
if err != nil {
return nil, err
}
return msg.(*et.ReplyAccountList), err
}
func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) { func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) {
signType := types.SECP256K1 signType := types.SECP256K1
c, err := crypto.New(types.GetSignName("", signType)) c, err := crypto.New(types.GetSignName("", signType))
......
...@@ -24,7 +24,7 @@ var ( ...@@ -24,7 +24,7 @@ var (
DefaultActiveTime = int64(5 * 360 * 24 * 3600) DefaultActiveTime = int64(5 * 360 * 24 * 3600)
//默认密钥重置锁定期 //默认密钥重置锁定期
DefaultLockTime = int64(15 * 24 * 3600) DefaultLockTime = int64(15 * 24 * 3600)
//默认管理员地址
DefaultManagerAddr = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" DefaultManagerAddr = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
) )
...@@ -48,9 +48,9 @@ func NewAction(e *accountmanager, tx *types.Transaction, index int) *Action { ...@@ -48,9 +48,9 @@ func NewAction(e *accountmanager, tx *types.Transaction, index int) *Action {
e.GetBlockTime(), e.GetHeight(), dapp.ExecAddress(string(tx.Execer)), e.GetLocalDB(), index, e.GetAPI()} e.GetBlockTime(), e.GetHeight(), dapp.ExecAddress(string(tx.Execer)), e.GetLocalDB(), index, e.GetAPI()}
} }
//GetIndex get index //GetIndex get index 主键索引
func (a *Action) GetIndex() int64 { func (a *Action) GetIndex() int64 {
return a.blocktime*int64(types.MaxTxsPerBlock) + int64(a.index) return a.height*types.MaxTxsPerBlock + int64(a.index)
} }
//GetKVSet get kv set //GetKVSet get kv set
...@@ -117,6 +117,7 @@ func (a *Action) Reset(payload *et.ResetKey) (*types.Receipt, error) { ...@@ -117,6 +117,7 @@ func (a *Action) Reset(payload *et.ResetKey) (*types.Receipt, error) {
func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) { func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kvs []*types.KeyValue var kvs []*types.KeyValue
cfg := a.api.GetConfig()
account1, err := findAccountByID(a.localDB, payload.FromAccountID) account1, err := findAccountByID(a.localDB, payload.FromAccountID)
if err != nil { if err != nil {
elog.Error("Transfer", "fromAccountID", payload.FromAccountID, "err", et.ErrAccountIDNotExist) elog.Error("Transfer", "fromAccountID", payload.FromAccountID, "err", et.ErrAccountIDNotExist)
...@@ -126,6 +127,33 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) { ...@@ -126,6 +127,33 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
elog.Error("Transfer", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss) elog.Error("Transfer", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss)
return nil, et.ErrAccountIDNotPermiss return nil, et.ErrAccountIDNotPermiss
} }
//如果prevAddr地址不为空,先查看余额,将该地址下面得资产划转到新得公钥地址下
if account1.PrevAddr != "" {
assetDB, err := account.NewAccountDB(cfg, payload.Asset.GetExecer(), payload.Asset.GetSymbol(), a.statedb)
if err != nil {
return nil, err
}
prevAccount := assetDB.LoadExecAccount(account1.PrevAddr, a.execaddr)
if prevAccount.Balance > 0 {
receipt, err := assetDB.ExecTransfer(account1.PrevAddr, account1.Addr, a.execaddr, prevAccount.Balance)
if err != nil {
return nil, err
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
}
}
if payload.FromAccountID == payload.ToAccountID {
re := &et.TransferReceipt{
FromAccount: account1,
ToAccount: account1,
Index: a.GetIndex(),
}
receiptlog := &types.ReceiptLog{Ty: et.TyTransferLog, Log: types.Encode(re)}
logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs}
return receipts, nil
}
account2, err := findAccountByID(a.localDB, payload.ToAccountID) account2, err := findAccountByID(a.localDB, payload.ToAccountID)
if err != nil { if err != nil {
elog.Error("Transfer,check to accountID", "toAccountID", payload.ToAccountID, "err", et.ErrAccountIDNotExist) elog.Error("Transfer,check to accountID", "toAccountID", payload.ToAccountID, "err", et.ErrAccountIDNotExist)
...@@ -135,7 +163,7 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) { ...@@ -135,7 +163,7 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
elog.Error("Transfer", "ToAccountID", account2.AccountID, "err", et.ErrAccountIDNotPermiss) elog.Error("Transfer", "ToAccountID", account2.AccountID, "err", et.ErrAccountIDNotPermiss)
return nil, et.ErrAccountIDNotPermiss return nil, et.ErrAccountIDNotPermiss
} }
cfg := a.api.GetConfig()
assetDB, err := account.NewAccountDB(cfg, payload.Asset.GetExecer(), payload.Asset.GetSymbol(), a.statedb) assetDB, err := account.NewAccountDB(cfg, payload.Asset.GetExecer(), payload.Asset.GetSymbol(), a.statedb)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -155,7 +183,7 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) { ...@@ -155,7 +183,7 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
re := &et.TransferReceipt{ re := &et.TransferReceipt{
FromAccount: account1, FromAccount: account1,
ToAccount: account2, ToAccount: account2,
BlockTime: a.blocktime, Index: a.GetIndex(),
} }
receiptlog := &types.ReceiptLog{Ty: et.TyTransferLog, Log: types.Encode(re)} receiptlog := &types.ReceiptLog{Ty: et.TyTransferLog, Log: types.Encode(re)}
logs = append(logs, receiptlog) logs = append(logs, receiptlog)
...@@ -170,31 +198,50 @@ func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) { ...@@ -170,31 +198,50 @@ func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) {
if managerAddr != a.fromaddr { if managerAddr != a.fromaddr {
return nil, et.ErrNotAdmin return nil, et.ErrNotAdmin
} }
coinsAssetDB, err := account.NewAccountDB(cfg, "coins", cfg.GetCoinSymbol(), a.statedb)
if err != nil {
return nil, err
}
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kvs []*types.KeyValue var kvs []*types.KeyValue
var re et.SuperviseReceipt var re et.SuperviseReceipt
for _, ID := range payload.AccountIDs { for _, ID := range payload.AccountIDs {
account, err := findAccountByID(a.localDB, ID) accountM, err := findAccountByID(a.localDB, ID)
if err != nil { if err != nil {
elog.Error("Supervise", "AccountID", ID, "err", et.ErrAccountIDNotExist) elog.Error("Supervise", "AccountID", ID, "err", et.ErrAccountIDNotExist)
return nil, et.ErrAccountIDNotExist return nil, et.ErrAccountIDNotExist
} }
switch re.Op { switch payload.Op {
case et.Freeze: case et.Freeze:
account.Status = et.Frozen //TODO 账户冻结,还需要冻结账户地址相应得资产,这里因为查不到所有token资产,所以只冻结主币
accountM.Status = et.Frozen
coinsAccount := coinsAssetDB.LoadExecAccount(accountM.Addr, a.execaddr)
receipt, err := coinsAssetDB.ExecFrozen(accountM.Addr, a.execaddr, coinsAccount.Balance)
if err != nil {
elog.Error("Supervise ExecFrozen", "AccountID", ID, "err", err)
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
case et.UnFreeze: case et.UnFreeze:
account.Status = et.Normal accountM.Status = et.Normal
coinsAccount := coinsAssetDB.LoadExecAccount(accountM.Addr, a.execaddr)
receipt, err := coinsAssetDB.ExecActive(accountM.Addr, a.execaddr, coinsAccount.Frozen)
if err != nil {
elog.Error("Supervise ExecActive", "AccountID", ID, "err", err)
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
case et.AddExpire: case et.AddExpire:
cfg := a.api.GetConfig() cfg := a.api.GetConfig()
defaultActiveTime := getConfValue(cfg, a.statedb, ConfNameActiveTime, DefaultActiveTime) defaultActiveTime := getConfValue(cfg, a.statedb, ConfNameActiveTime, DefaultActiveTime)
account.Status = et.Normal accountM.Status = et.Normal
account.ExpireTime = a.blocktime + defaultActiveTime accountM.ExpireTime = a.blocktime + defaultActiveTime
} }
re.Accounts = append(re.Accounts, account) re.Accounts = append(re.Accounts, accountM)
} }
re.Op = payload.Op re.Op = payload.Op
re.BlockTime = a.blocktime re.Index = a.GetIndex()
receiptlog := &types.ReceiptLog{Ty: et.TySuperviseLog, Log: types.Encode(&re)} receiptlog := &types.ReceiptLog{Ty: et.TySuperviseLog, Log: types.Encode(&re)}
logs = append(logs, receiptlog) logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs} receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs}
...@@ -203,37 +250,52 @@ func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) { ...@@ -203,37 +250,52 @@ func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) {
func (a *Action) Apply(payload *et.Apply) (*types.Receipt, error) { func (a *Action) Apply(payload *et.Apply) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
account, err := findAccountByID(a.localDB, payload.AccountID) var kvs []*types.KeyValue
accountM, err := findAccountByID(a.localDB, payload.AccountID)
if err != nil { if err != nil {
elog.Error("Apply", "AccountID", payload.AccountID, "err", et.ErrAccountIDNotExist) elog.Error("Apply", "AccountID", payload.AccountID, "err", et.ErrAccountIDNotExist)
return nil, et.ErrAccountIDNotExist return nil, et.ErrAccountIDNotExist
} }
switch payload.Op { switch payload.Op {
case et.RevokeReset: case et.RevokeReset:
if account.Status != et.Locked || account.PrevAddr != a.fromaddr { if accountM.Status != et.Locked || accountM.PrevAddr != a.fromaddr {
elog.Error("Apply", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss) elog.Error("Apply", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss)
return nil, et.ErrAccountIDNotPermiss return nil, et.ErrAccountIDNotPermiss
} }
account.LockTime = 0 accountM.LockTime = 0
account.Status = et.Normal accountM.Status = et.Normal
account.Addr = a.fromaddr accountM.Addr = a.fromaddr
case et.EnforceReset: case et.EnforceReset:
if account.Status != et.Locked || account.Addr != a.fromaddr { if accountM.Status != et.Locked || accountM.Addr != a.fromaddr {
elog.Error("Apply", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss) elog.Error("Apply", "fromaddr", a.fromaddr, "err", et.ErrAccountIDNotPermiss)
return nil, et.ErrAccountIDNotPermiss return nil, et.ErrAccountIDNotPermiss
} }
account.LockTime = 0 accountM.LockTime = 0
account.Status = et.Normal accountM.Status = et.Normal
//TODO 资产转移,放在转transfer中执行 //TODO 这里只做coins主笔资产得自动划转,token资产转移,放在转transfer中执行 fromAccountID == toAccountID
cfg := a.api.GetConfig()
coinsAssetDB, err := account.NewAccountDB(cfg, "coins", cfg.GetCoinSymbol(), a.statedb)
if err != nil {
return nil, err
}
coinsAccount := coinsAssetDB.LoadExecAccount(accountM.PrevAddr, a.execaddr)
receipt, err := coinsAssetDB.ExecTransfer(accountM.PrevAddr, accountM.Addr, a.execaddr, coinsAccount.Balance)
if err != nil {
elog.Error("Apply ExecTransfer", "AccountID", accountM.AccountID, "err", err)
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
} }
re := &et.AccountReceipt{ re := &et.AccountReceipt{
Account: account, Account: accountM,
} }
receiptlog := &types.ReceiptLog{Ty: et.TyApplyLog, Log: types.Encode(re)} receiptlog := &types.ReceiptLog{Ty: et.TyApplyLog, Log: types.Encode(re)}
logs = append(logs, receiptlog) logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs} receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs}
return receipts, nil return receipts, nil
} }
...@@ -308,24 +370,26 @@ func getConfigKey(key string, db dbm.KV) ([]byte, error) { ...@@ -308,24 +370,26 @@ func getConfigKey(key string, db dbm.KV) ([]byte, error) {
return value, nil return value, nil
} }
func findAccountListByIndex(localdb dbm.KV, direction int32, primaryKey string) (*et.ReplyAccountList, error) { //正序遍历数据,与传入时间进行对比,看是否逾期
func findAccountListByIndex(localdb dbm.KV, expireTime int64, primaryKey string) (*et.ReplyAccountList, error) {
table := NewAccountTable(localdb) table := NewAccountTable(localdb)
first := []byte(fmt.Sprintf("%016d", time.Now().Unix()*int64(types.MaxTxsPerBlock)))
var rows []*tab.Row var rows []*tab.Row
var err error var err error
if primaryKey == "" { //第一次查询,默认展示最新得成交记录 if primaryKey == "" { //第一次查询,默认展示最新得成交记录
rows, err = table.ListIndex("index", nil, first, et.Count, direction) rows, err = table.ListIndex("index", nil, nil, et.Count, et.ListASC)
} else { } else {
rows, err = table.ListIndex("index", nil, []byte(primaryKey), et.Count, direction) rows, err = table.ListIndex("index", nil, []byte(primaryKey), et.Count, et.ListASC)
} }
if err != nil { if err != nil {
elog.Error("findAccountListByIndex.", "index", first, "err", err.Error()) elog.Error("findAccountListByIndex.", "index", primaryKey, "err", err.Error())
return nil, err return nil, err
} }
var reply et.ReplyAccountList var reply et.ReplyAccountList
for _, row := range rows { for _, row := range rows {
account := row.Data.(*et.Account) account := row.Data.(*et.Account)
if account.ExpireTime > expireTime {
break
}
//状态变成逾期状态 //状态变成逾期状态
account.Status = et.Expired account.Status = et.Expired
reply.Accounts = append(reply.Accounts, account) reply.Accounts = append(reply.Accounts, account)
...@@ -353,9 +417,25 @@ func findAccountByID(localdb dbm.KV, accountID string) (*et.Account, error) { ...@@ -353,9 +417,25 @@ func findAccountByID(localdb dbm.KV, accountID string) (*et.Account, error) {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
func findAccountByAddr(localdb dbm.KV, addr string) (*et.Account, error) {
table := NewAccountTable(localdb)
prefix := []byte(fmt.Sprintf("%s", addr))
//第一次查询,默认展示最新得成交记录
rows, err := table.ListIndex("addr", prefix, nil, 1, et.ListDESC)
if err != nil {
elog.Error("findAccountByAddr.", "prefix", prefix, "err", err.Error())
return nil, err
}
for _, row := range rows {
account := row.Data.(*et.Account)
return account, nil
}
return nil, types.ErrNotFound
}
func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey string) (*et.ReplyAccountList, error) { func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey string) (*et.ReplyAccountList, error) {
if status == et.Expired { if status == et.Expired {
return findAccountListByIndex(localdb, direction, primaryKey) return findAccountListByIndex(localdb, time.Now().Unix(), primaryKey)
} }
table := NewAccountTable(localdb) table := NewAccountTable(localdb)
prefix := []byte(fmt.Sprintf("%d", status)) prefix := []byte(fmt.Sprintf("%d", status))
...@@ -368,7 +448,7 @@ func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey ...@@ -368,7 +448,7 @@ func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey
rows, err = table.ListIndex("status", prefix, []byte(primaryKey), et.Count, direction) rows, err = table.ListIndex("status", prefix, []byte(primaryKey), et.Count, direction)
} }
if err != nil { if err != nil {
elog.Error("findAccountListByStatus.", "status", prefix, "err", err.Error()) elog.Error("findAccountListByStatus.", "status", status, "err", err.Error())
return nil, err return nil, err
} }
var reply et.ReplyAccountList var reply et.ReplyAccountList
...@@ -382,3 +462,24 @@ func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey ...@@ -382,3 +462,24 @@ func findAccountListByStatus(localdb dbm.KV, status, direction int32, primaryKey
} }
return &reply, nil return &reply, nil
} }
func queryBalanceByID(statedb, localdb dbm.KV, cfg *types.Chain33Config, execName string, in *et.QueryBalanceByID) (*et.Balance, error) {
acc, err := findAccountByID(localdb, in.AccountID)
if err != nil {
return nil, err
}
assetDB, err := account.NewAccountDB(cfg, in.Asset.GetExecer(), in.Asset.GetSymbol(), statedb)
if err != nil {
return nil, err
}
var balance et.Balance
if acc.PrevAddr != "" {
prevAccount := assetDB.LoadExecAccount(acc.PrevAddr, dapp.ExecAddress(execName))
balance.Balance += prevAccount.Balance
balance.Frozen += prevAccount.Frozen
}
currAccount := assetDB.LoadExecAccount(acc.Addr, dapp.ExecAddress(execName))
balance.Balance += currAccount.Balance
balance.Frozen += currAccount.Frozen
return &balance, nil
}
...@@ -15,7 +15,7 @@ func (a *accountmanager) Exec_Register(payload *aty.Register, tx *types.Transact ...@@ -15,7 +15,7 @@ func (a *accountmanager) Exec_Register(payload *aty.Register, tx *types.Transact
return action.Register(payload) return action.Register(payload)
} }
func (a *accountmanager) Exec_Resetkey(payload *aty.ResetKey, tx *types.Transaction, index int) (*types.Receipt, error) { func (a *accountmanager) Exec_ResetKey(payload *aty.ResetKey, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index) action := NewAction(a, tx, index)
return action.Reset(payload) return action.Reset(payload)
} }
...@@ -31,5 +31,6 @@ func (a *accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transa ...@@ -31,5 +31,6 @@ func (a *accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transa
} }
func (a *accountmanager) Exec_Apply(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) {
return nil, types.ErrActionNotSupport action := NewAction(a, tx, index)
return action.Apply(payload)
} }
...@@ -94,7 +94,20 @@ func (a *accountmanager) ExecLocal_Transfer(payload *et.Transfer, tx *types.Tran ...@@ -94,7 +94,20 @@ func (a *accountmanager) ExecLocal_Transfer(payload *et.Transfer, tx *types.Tran
for _, log := range receiptData.Logs { for _, log := range receiptData.Logs {
switch log.Ty { switch log.Ty {
case et.TyResetLog: case et.TyResetLog:
//账户信息不变更,不需要处理 receipt := &et.TransferReceipt{}
if err := types.Decode(log.Log, receipt); err != nil {
return nil, err
}
accountTable := NewAccountTable(a.GetLocalDB())
err := accountTable.Replace(receipt.FromAccount)
if err != nil {
return nil, err
}
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
} }
} }
} }
...@@ -112,17 +125,39 @@ func (a *accountmanager) ExecLocal_Supervise(payload *et.Supervise, tx *types.Tr ...@@ -112,17 +125,39 @@ func (a *accountmanager) ExecLocal_Supervise(payload *et.Supervise, tx *types.Tr
return nil, err return nil, err
} }
accountTable := NewAccountTable(a.GetLocalDB()) accountTable := NewAccountTable(a.GetLocalDB())
for _, account := range receipt.Accounts { //当时续期操作得话,需要重建
err := accountTable.Replace(account) if receipt.Op == et.AddExpire {
for _, account := range receipt.Accounts {
err := accountTable.DelRow(account)
if err != nil {
return nil, err
}
//重置主键
account.Index = receipt.Index
err = accountTable.Replace(account)
if err != nil {
return nil, err
}
}
kvs, err := accountTable.Save()
if err != nil { if err != nil {
return nil, err return nil, err
} }
dbSet.KV = append(dbSet.KV, kvs...)
} else {
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...)
} }
kvs, err := accountTable.Save()
if err != nil {
return nil, err
}
dbSet.KV = append(dbSet.KV, kvs...)
} }
} }
} }
......
...@@ -10,6 +10,11 @@ func (s *accountmanager) Query_QueryAccountByID(in *et.QueryAccountByID) (types. ...@@ -10,6 +10,11 @@ func (s *accountmanager) Query_QueryAccountByID(in *et.QueryAccountByID) (types.
return findAccountByID(s.GetLocalDB(), in.AccountID) return findAccountByID(s.GetLocalDB(), in.AccountID)
} }
//根据ID查询账户信息
func (s *accountmanager) Query_QueryAccountByAddr(in *et.QueryAccountByAddr) (types.Message, error) {
return findAccountByAddr(s.GetLocalDB(), in.Addr)
}
//根据状态查询账户列表|| 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销 //根据状态查询账户列表|| 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
func (s *accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatus) (types.Message, error) { func (s *accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatus) (types.Message, error) {
return findAccountListByStatus(s.GetLocalDB(), in.Status, in.Direction, in.PrimaryKey) return findAccountListByStatus(s.GetLocalDB(), in.Status, in.Direction, in.PrimaryKey)
...@@ -17,5 +22,10 @@ func (s *accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatu ...@@ -17,5 +22,10 @@ func (s *accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatu
//查询逾期注销的账户列表 //查询逾期注销的账户列表
func (s *accountmanager) Query_QueryExpiredAccounts(in *et.QueryExpiredAccounts) (types.Message, error) { func (s *accountmanager) Query_QueryExpiredAccounts(in *et.QueryExpiredAccounts) (types.Message, error) {
return findAccountListByIndex(s.GetLocalDB(), in.Direction, in.PrimaryKey) return findAccountListByIndex(s.GetLocalDB(), in.ExpiredTime, in.PrimaryKey)
}
//根据ID查询账户余额
func (s *accountmanager) Query_QueryBalanceByID(in *et.QueryBalanceByID) (types.Message, error) {
return queryBalanceByID(s.GetStateDB(), s.GetLocalDB(), s.GetAPI().GetConfig(), s.GetName(), in)
} }
...@@ -25,7 +25,7 @@ var opt_account = &table.Option{ ...@@ -25,7 +25,7 @@ var opt_account = &table.Option{
Prefix: KeyPrefixLocalDB, Prefix: KeyPrefixLocalDB,
Name: "account", Name: "account",
Primary: "index", Primary: "index",
Index: []string{"status", "accountID"}, Index: []string{"status", "accountID", "addr"},
} }
//状态数据库中存储具体账户信息 //状态数据库中存储具体账户信息
...@@ -74,7 +74,9 @@ func (m *AccountRow) Get(key string) ([]byte, error) { ...@@ -74,7 +74,9 @@ func (m *AccountRow) Get(key string) ([]byte, error) {
} 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" { } else if key == "index" {
return []byte(fmt.Sprintf("%014d", m.GetIndex())), nil return []byte(fmt.Sprintf("%018d", m.GetIndex())), nil
} else if key == "addr" {
return []byte(fmt.Sprintf("%s", m.GetAddr())), nil
} }
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
package executor package executor
import ( import (
"fmt" "github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
"testing" "testing"
"time"
) )
func Test(t *testing.T) { func TestAccountTable(t *testing.T) {
t.Log(fmt.Sprintf("%-s", "aaaa100000b")) _, _, kvdb := util.CreateTestDB()
} table:=NewAccountTable(kvdb)
now :=time.Now().Unix()
row1:= &et.Account{Index:now*int64(types.MaxTxsPerBlock),AccountID:"harry2015",Status:1,ExpireTime:now+10,Addr:"xxxx"}
row2:= &et.Account{Index:now*int64(types.MaxTxsPerBlock)+1,AccountID:"harry2020",Status:1,ExpireTime:now,Addr:"xxxx"}
table.Add(row1)
table.Add(row2)
kvs,err:=table.Save()
if err !=nil {
t.Error(err)
}
for _,kv :=range kvs{
kvdb.Set(kv.Key,kv.Value)
}
time.Sleep(2*time.Second)
list,err:=findAccountListByIndex(kvdb,time.Now().Unix(),"")
if err !=nil {
t.Error(err)
}
t.Log(list)
list,err=findAccountListByStatus(kvdb,et.Normal,0,"")
if err !=nil {
t.Error(err)
}
t.Log(list)
row1.Status=et.Frozen
err=table.Replace(row1)
if err !=nil {
t.Error(err)
}
kvs,err=table.Save()
if err !=nil {
t.Error(err)
}
for _,kv :=range kvs{
kvdb.Set(kv.Key,kv.Value)
}
list,err=findAccountListByStatus(kvdb,et.Frozen,0,"")
if err !=nil {
t.Error(err)
}
t.Log(list)
}
\ No newline at end of file
...@@ -100,21 +100,24 @@ message TransferReceipt{ ...@@ -100,21 +100,24 @@ message TransferReceipt{
account ToAccount = 2; account ToAccount = 2;
int64 blockTime = 3; int64 index = 3;
} }
//回执日志 //回执日志
message SuperviseReceipt{ message SuperviseReceipt{
repeated account accounts = 1; repeated account accounts = 1;
int32 op = 2; int32 op = 2;
int64 blockTime = 3; int64 index = 3;
} }
message QueryExpiredAccounts{ message QueryExpiredAccounts{
string primaryKey = 1; string primaryKey = 1;
//第一次需要传入逾期时间,时间戳
int64 expiredTime = 2;
//单页返回多少条记录,默认返回10条 //单页返回多少条记录,默认返回10条
// 0降序,1升序,默认降序 // 0降序,1升序,默认降序
int32 direction = 2; int32 direction = 3;
} }
message QueryAccountsByStatus{ message QueryAccountsByStatus{
...@@ -129,6 +132,21 @@ message QueryAccountsByStatus{ ...@@ -129,6 +132,21 @@ message QueryAccountsByStatus{
message QueryAccountByID { message QueryAccountByID {
string accountID = 1; string accountID = 1;
} }
message QueryAccountByAddr {
string addr = 1;
}
message QueryBalanceByID {
string accountID = 1;
asset asset = 2;
}
message balance {
int64 balance = 1;
int64 frozen = 2;
}
service accountmanager { service accountmanager {
} }
...@@ -30,6 +30,8 @@ const ( ...@@ -30,6 +30,8 @@ const (
FuncNameQueryAccountByID = "QueryAccountByID" FuncNameQueryAccountByID = "QueryAccountByID"
FuncNameQueryAccountsByStatus = "QueryAccountsByStatus" FuncNameQueryAccountsByStatus = "QueryAccountsByStatus"
FuncNameQueryExpiredAccounts = "QueryExpiredAccounts" FuncNameQueryExpiredAccounts = "QueryExpiredAccounts"
FuncNameQueryAccountByAddr = "QueryAccountByAddr"
FuncNameQueryBalanceByID = "QueryBalanceByID"
) )
// log类型id值 // log类型id值
......
...@@ -24,6 +24,9 @@ It has these top-level messages: ...@@ -24,6 +24,9 @@ It has these top-level messages:
QueryExpiredAccounts QueryExpiredAccounts
QueryAccountsByStatus QueryAccountsByStatus
QueryAccountByID QueryAccountByID
QueryAccountByAddr
QueryBalanceByID
Balance
*/ */
package types package types
...@@ -565,7 +568,7 @@ func (m *ReplyAccountList) GetPrimaryKey() string { ...@@ -565,7 +568,7 @@ func (m *ReplyAccountList) GetPrimaryKey() string {
type TransferReceipt struct { type TransferReceipt struct {
FromAccount *Account `protobuf:"bytes,1,opt,name=FromAccount" json:"FromAccount,omitempty"` FromAccount *Account `protobuf:"bytes,1,opt,name=FromAccount" json:"FromAccount,omitempty"`
ToAccount *Account `protobuf:"bytes,2,opt,name=ToAccount" json:"ToAccount,omitempty"` ToAccount *Account `protobuf:"bytes,2,opt,name=ToAccount" json:"ToAccount,omitempty"`
BlockTime int64 `protobuf:"varint,3,opt,name=blockTime" json:"blockTime,omitempty"` Index int64 `protobuf:"varint,3,opt,name=index" json:"index,omitempty"`
} }
func (m *TransferReceipt) Reset() { *m = TransferReceipt{} } func (m *TransferReceipt) Reset() { *m = TransferReceipt{} }
...@@ -587,18 +590,18 @@ func (m *TransferReceipt) GetToAccount() *Account { ...@@ -587,18 +590,18 @@ func (m *TransferReceipt) GetToAccount() *Account {
return nil return nil
} }
func (m *TransferReceipt) GetBlockTime() int64 { func (m *TransferReceipt) GetIndex() int64 {
if m != nil { if m != nil {
return m.BlockTime return m.Index
} }
return 0 return 0
} }
// 回执日志 // 回执日志
type SuperviseReceipt struct { type SuperviseReceipt struct {
Accounts []*Account `protobuf:"bytes,1,rep,name=accounts" json:"accounts,omitempty"` Accounts []*Account `protobuf:"bytes,1,rep,name=accounts" json:"accounts,omitempty"`
Op int32 `protobuf:"varint,2,opt,name=op" json:"op,omitempty"` Op int32 `protobuf:"varint,2,opt,name=op" json:"op,omitempty"`
BlockTime int64 `protobuf:"varint,3,opt,name=blockTime" json:"blockTime,omitempty"` Index int64 `protobuf:"varint,3,opt,name=index" json:"index,omitempty"`
} }
func (m *SuperviseReceipt) Reset() { *m = SuperviseReceipt{} } func (m *SuperviseReceipt) Reset() { *m = SuperviseReceipt{} }
...@@ -620,18 +623,20 @@ func (m *SuperviseReceipt) GetOp() int32 { ...@@ -620,18 +623,20 @@ func (m *SuperviseReceipt) GetOp() int32 {
return 0 return 0
} }
func (m *SuperviseReceipt) GetBlockTime() int64 { func (m *SuperviseReceipt) GetIndex() int64 {
if m != nil { if m != nil {
return m.BlockTime return m.Index
} }
return 0 return 0
} }
type QueryExpiredAccounts struct { type QueryExpiredAccounts struct {
PrimaryKey string `protobuf:"bytes,1,opt,name=primaryKey" json:"primaryKey,omitempty"` PrimaryKey string `protobuf:"bytes,1,opt,name=primaryKey" json:"primaryKey,omitempty"`
// 第一次需要传入逾期时间,时间戳
ExpiredTime int64 `protobuf:"varint,2,opt,name=expiredTime" json:"expiredTime,omitempty"`
// 单页返回多少条记录,默认返回10条 // 单页返回多少条记录,默认返回10条
// 0降序,1升序,默认降序 // 0降序,1升序,默认降序
Direction int32 `protobuf:"varint,2,opt,name=direction" json:"direction,omitempty"` Direction int32 `protobuf:"varint,3,opt,name=direction" json:"direction,omitempty"`
} }
func (m *QueryExpiredAccounts) Reset() { *m = QueryExpiredAccounts{} } func (m *QueryExpiredAccounts) Reset() { *m = QueryExpiredAccounts{} }
...@@ -646,6 +651,13 @@ func (m *QueryExpiredAccounts) GetPrimaryKey() string { ...@@ -646,6 +651,13 @@ func (m *QueryExpiredAccounts) GetPrimaryKey() string {
return "" return ""
} }
func (m *QueryExpiredAccounts) GetExpiredTime() int64 {
if m != nil {
return m.ExpiredTime
}
return 0
}
func (m *QueryExpiredAccounts) GetDirection() int32 { func (m *QueryExpiredAccounts) GetDirection() int32 {
if m != nil { if m != nil {
return m.Direction return m.Direction
...@@ -704,6 +716,70 @@ func (m *QueryAccountByID) GetAccountID() string { ...@@ -704,6 +716,70 @@ func (m *QueryAccountByID) GetAccountID() string {
return "" return ""
} }
type QueryAccountByAddr struct {
Addr string `protobuf:"bytes,1,opt,name=addr" json:"addr,omitempty"`
}
func (m *QueryAccountByAddr) Reset() { *m = QueryAccountByAddr{} }
func (m *QueryAccountByAddr) String() string { return proto.CompactTextString(m) }
func (*QueryAccountByAddr) ProtoMessage() {}
func (*QueryAccountByAddr) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} }
func (m *QueryAccountByAddr) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
type QueryBalanceByID struct {
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
Asset *Asset `protobuf:"bytes,2,opt,name=asset" json:"asset,omitempty"`
}
func (m *QueryBalanceByID) Reset() { *m = QueryBalanceByID{} }
func (m *QueryBalanceByID) String() string { return proto.CompactTextString(m) }
func (*QueryBalanceByID) ProtoMessage() {}
func (*QueryBalanceByID) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} }
func (m *QueryBalanceByID) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
func (m *QueryBalanceByID) GetAsset() *Asset {
if m != nil {
return m.Asset
}
return nil
}
type Balance struct {
Balance int64 `protobuf:"varint,1,opt,name=balance" json:"balance,omitempty"`
Frozen int64 `protobuf:"varint,2,opt,name=frozen" json:"frozen,omitempty"`
}
func (m *Balance) Reset() { *m = Balance{} }
func (m *Balance) String() string { return proto.CompactTextString(m) }
func (*Balance) ProtoMessage() {}
func (*Balance) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18} }
func (m *Balance) GetBalance() int64 {
if m != nil {
return m.Balance
}
return 0
}
func (m *Balance) GetFrozen() int64 {
if m != nil {
return m.Frozen
}
return 0
}
func init() { func init() {
proto.RegisterType((*Accountmanager)(nil), "types.Accountmanager") proto.RegisterType((*Accountmanager)(nil), "types.Accountmanager")
proto.RegisterType((*AccountmanagerAction)(nil), "types.AccountmanagerAction") proto.RegisterType((*AccountmanagerAction)(nil), "types.AccountmanagerAction")
...@@ -721,6 +797,9 @@ func init() { ...@@ -721,6 +797,9 @@ func init() {
proto.RegisterType((*QueryExpiredAccounts)(nil), "types.QueryExpiredAccounts") proto.RegisterType((*QueryExpiredAccounts)(nil), "types.QueryExpiredAccounts")
proto.RegisterType((*QueryAccountsByStatus)(nil), "types.QueryAccountsByStatus") proto.RegisterType((*QueryAccountsByStatus)(nil), "types.QueryAccountsByStatus")
proto.RegisterType((*QueryAccountByID)(nil), "types.QueryAccountByID") proto.RegisterType((*QueryAccountByID)(nil), "types.QueryAccountByID")
proto.RegisterType((*QueryAccountByAddr)(nil), "types.QueryAccountByAddr")
proto.RegisterType((*QueryBalanceByID)(nil), "types.QueryBalanceByID")
proto.RegisterType((*Balance)(nil), "types.balance")
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
...@@ -764,46 +843,50 @@ var _Accountmanager_serviceDesc = grpc.ServiceDesc{ ...@@ -764,46 +843,50 @@ var _Accountmanager_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("accountmanager.proto", fileDescriptor0) } func init() { proto.RegisterFile("accountmanager.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 647 bytes of a gzipped FileDescriptorProto // 719 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x4d, 0x6f, 0xd3, 0x40, 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f1, 0xb0, 0x6f, 0xbd, 0xa5, 0x70, 0x23, 0xd9, 0xd1, 0x68, 0x6d, 0x29, 0xfc, 0xa1, 0xa7, 0xd0,
0xbb, 0x32, 0x0e, 0x49, 0x54, 0x7e, 0xa2, 0x2b, 0x9f, 0x95, 0xcc, 0x01, 0x74, 0xaf, 0x65, 0xfa,
0x5d, 0xac, 0x6d, 0x03, 0xac, 0x75, 0x32, 0x84, 0x41, 0xf3, 0x3f, 0xf3, 0xaa, 0x8b, 0x7f, 0x9a,
0xaf, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x71, 0xbc, 0x47, 0xe4, 0x4c, 0x07, 0x00, 0x00,
} }
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