diff --git a/transfer/transfer_manager.go b/transfer/transfer_manager.go index 7b705f91e31557d49a13138c6e21c99c94f05ba7..3ff6c289fd7b87e6c825598fd05f9047f7bf897a 100644 --- a/transfer/transfer_manager.go +++ b/transfer/transfer_manager.go @@ -1,7 +1,8 @@ package transfer import ( - "chainmaker.org/chainmaker/pb-go/v2/vm" + "chainmaker.org/chainmaker/pb-go/v2/syscontract" + vmPb "chainmaker.org/chainmaker/pb-go/v2/vm" "chainmaker.org/chainmaker/protocol/v2" "chainmaker.org/chainmaker/vm-native/v2/common" "encoding/json" @@ -9,10 +10,25 @@ import ( "strconv" ) -const contractName = "transfer" +var contractName = syscontract.Pallet_Transfer.String() + const empty = "" -// AccountManagerRuntime comment at next version +const ( + Method_INIT = "init" + Method_TRANSFER = "transfer" +) +const ( + InitParams_BALANCE = "balance" + InitParams_STARTINDEX = "startIndex" + InitParams_ENDINDEX = "endIndex" +) +const ( + TransferParams_FROM = "f" + TransferParams_TO = "t" + TransferParams_Trans = "b" +) + type TransferManagerRuntime struct { log protocol.Logger } @@ -54,9 +70,9 @@ func registerTransferContractMethods(log protocol.Logger) map[string]common.Cont methodMap := make(map[string]common.ContractFunc, 64) gasAccountRuntime := &TransferManagerRuntime{log: log} - methodMap["init"] = common.WrapResultFunc( + methodMap[Method_INIT] = common.WrapResultFunc( gasAccountRuntime.Init) - methodMap["transfer"] = common.WrapResultFunc( + methodMap[Method_TRANSFER] = common.WrapResultFunc( gasAccountRuntime.Transfer) return methodMap @@ -65,9 +81,9 @@ func registerTransferContractMethods(log protocol.Logger) map[string]common.Cont func (t *TransferManagerRuntime) Init(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error) { - balance := string(params["balance"]) - startIndex := string(params["startIndex"]) // 分批创建账户 - start index - endIndex := string(params["endIndex"]) // 分批创建账户 - end index + balance := string(params[InitParams_BALANCE]) + startIndex := string(params[InitParams_STARTINDEX]) // 分批创建账户 - start index + endIndex := string(params[InitParams_ENDINDEX]) // 分批创建账户 - end index start, _ := strconv.Atoi(startIndex) end, _ := strconv.Atoi(endIndex) @@ -81,10 +97,10 @@ func (t *TransferManagerRuntime) Init(txSimContext protocol.TxSimContext, func (t *TransferManagerRuntime) Transfer(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error) { - from := string(params["f"]) - to := string(params["f"]) - trans, _ := strconv.Atoi(string("t")) - keys := []*vm.BatchKey{ + from := string(params[TransferParams_FROM]) + to := string(params[TransferParams_TO]) + trans, _ := strconv.Atoi(string(params[TransferParams_Trans])) + keys := []*vmPb.BatchKey{ {from, empty, nil, contractName}, {to, empty, nil, contractName}, }