Skip to content

Commit

Permalink
modify withdraw with userid
Browse files Browse the repository at this point in the history
  • Loading branch information
rockneiep committed Apr 28, 2019
1 parent cd95584 commit d260b19
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions processor/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var (
errMaxCodeSizeExceeded = errors.New("evm: max code size exceeded")
)

const (
AccountFee = 1
AssetFee = 2
)

func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
x, y := stack.pop(), stack.peek()
math.U256(y.Add(x, y))
Expand Down Expand Up @@ -1308,23 +1313,38 @@ func execSetAssetOwner(evm *EVM, contract *Contract, assetID uint64, owner commo

//withdraw all asset fee from system
func opWithdrawFee(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
to := stack.pop()
userID := to.Uint64()
acct, err := evm.AccountDB.GetAccountById(userID)
if err != nil || acct == nil {
feeType, feeId := stack.pop(), stack.pop()
withdrawType := feeType.Uint64()
objID := feeId.Uint64()

var name common.Name
if withdrawType == AccountFee {
acct, err := evm.AccountDB.GetAccountById(objID)
if err != nil || acct == nil {
stack.push(evm.interpreter.intPool.getZero())
return nil, err
}
name = acct.GetName()
} else if withdrawType == AssetFee {
assetInfo, err := evm.AccountDB.GetAssetInfoByID(objID)
if err != nil || assetInfo == nil {
stack.push(evm.interpreter.intPool.getZero())
return nil, err
}
name = common.Name(assetInfo.GetAssetName())
} else {
stack.push(evm.interpreter.intPool.getZero())
return nil, nil
return nil, fmt.Errorf("object type not correct")
}
name := acct.GetName()

err = execWithdrawFee(evm, contract, name)
err := execWithdrawFee(evm, contract, name)

if err != nil {
stack.push(evm.interpreter.intPool.getZero())
} else {
stack.push(evm.interpreter.intPool.get().SetUint64(1))
}
evm.interpreter.intPool.put(to)
evm.interpreter.intPool.put(feeType, feeId)

return nil, err
}
Expand Down

0 comments on commit d260b19

Please sign in to comment.