Skip to content

Commit

Permalink
change AccountData to include Address
Browse files Browse the repository at this point in the history
  • Loading branch information
studyzy committed Feb 20, 2019
1 parent 48f0f41 commit b76d7b4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
22 changes: 1 addition & 21 deletions dag/common/unit_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,27 +603,7 @@ func GenGenesisConfigPayload(genesisConf *core.Genesis, asset *modules.Asset) (*

func (rep *UnitRepository) saveAccountData(payload *modules.AccountDataPayload, height *modules.ChainIndex, txIndex uint32) error {
version := &modules.StateVersion{Height: height, TxIndex: txIndex}
return rep.statedb.SaveAccountData(payload.AccountId, payload.WriteSet, version)

//// type deduct
//VotePayLoad, ok := msg.Payload.(*vote.VoteInfo)
//if !ok {
// return errors.New("not a valid vote payload")
//}
//
//// save by type
//switch {
//case VotePayLoad.VoteType == vote.TypeMediator:
// //Addresses := common.BytesListToAddressList(VotePayLoad.Contents)
// mediator := common.BytesToAddress(VotePayLoad.Contents)
//
// if err := rep.statedb.AppendVotedMediator(voter, mediator); err != nil {
// return err
// }
//
//}
//return nil

return rep.statedb.SaveAccountData(payload.Account, payload.WriteSet, version)
}

//Get who send this transaction
Expand Down
15 changes: 15 additions & 0 deletions dag/modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DAG相关模型设计

## Message
### PaymentPayload
所有关于Token的流转都使用该Message
### DataPayload
存证用
### ContractInvokeRequest
用户发起合约调用请求
### ContractInvoke
Mediator或者Jury执行合约后的执行结果,主要包含读写集
### AccountData
用户自己的状态数据空间,只有用户可以修改,包含了Mediator的投票结果
### Signature
在合约执行完毕后,Mediator或者Jury对包含执行结果的Tx的签名
6 changes: 4 additions & 2 deletions dag/modules/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,11 @@ type ContractInvokeResult struct {
TokenSupply []*TokenSupply `json:"token_supply"` //增发Token请求产生的结果
TokenDefine *TokenDefine `json:"token_define"` //定义新Token
}

//每个账户拥有自己的存储空间
type AccountDataPayload struct {
AccountId []byte `json:"account_id"` // account id
WriteSet []ContractWriteSet `json:"write_set"` // the set data of write, and value could be any type
Account common.Address `json:"account"` // account id
WriteSet []ContractWriteSet `json:"write_set"` // the set data of write, and value could be any type
}

//用户钱包发起的合约调用申请
Expand Down
9 changes: 6 additions & 3 deletions dag/storage/statedb_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func getAccountDataKey(id []byte, field string) []byte {
key := append(constants.ACCOUNT_DATA_PREFIX, id...)
return append(key, []byte(field)...)
}
func (statedb *StateDb) SaveAccountData(accountId []byte, wset []modules.ContractWriteSet, version *modules.StateVersion) error {
func (statedb *StateDb) SaveAccountData(account common.Address, wset []modules.ContractWriteSet, version *modules.StateVersion) error {
accountId := account.Bytes()
batch := statedb.db.NewBatch()
for _, write := range wset {
key := getAccountDataKey(accountId, write.Key)
Expand All @@ -191,7 +192,8 @@ func (statedb *StateDb) SaveAccountData(accountId []byte, wset []modules.Contrac

return nil
}
func (statedb *StateDb) GetAccountAllData(accountId []byte) (map[string]*modules.ContractStateValue, error) {
func (statedb *StateDb) GetAccountAllData(account common.Address) (map[string]*modules.ContractStateValue, error) {
accountId := account.Bytes()
key := append(constants.ACCOUNT_DATA_PREFIX, accountId...)
data := getprefix(statedb.db, key)
if data == nil || len(data) == 0 {
Expand All @@ -212,7 +214,8 @@ func (statedb *StateDb) GetAccountAllData(accountId []byte) (map[string]*modules
}
return result, err
}
func (statedb *StateDb) GetAccountOneData(accountId []byte, key string) ([]byte, *modules.StateVersion, error) {
func (statedb *StateDb) GetAccountOneData(account common.Address, key string) ([]byte, *modules.StateVersion, error) {
accountId := account.Bytes()
key1 := getAccountDataKey(accountId, key)
data, version, err := retrieveWithVersion(statedb.db, key1)
return data, version, err
Expand Down
6 changes: 3 additions & 3 deletions dag/storage/statedb_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type IStateDb interface {
IsMediator(address common.Address) bool
LookupAccount() map[common.Address]*modules.AccountInfo
RetrieveMediatorInfo(address common.Address) (*modules.MediatorInfo, error)
SaveAccountData(accountId []byte, wset []modules.ContractWriteSet, version *modules.StateVersion) error
GetAccountAllData(accountId []byte) (map[string]*modules.ContractStateValue, error)
GetAccountOneData(accountId []byte, key string) ([]byte, *modules.StateVersion, error)
SaveAccountData(account common.Address, wset []modules.ContractWriteSet, version *modules.StateVersion) error
GetAccountAllData(account common.Address) (map[string]*modules.ContractStateValue, error)
GetAccountOneData(account common.Address, key string) ([]byte, *modules.StateVersion, error)
}

0 comments on commit b76d7b4

Please sign in to comment.