Skip to content

Commit

Permalink
Add transfer support
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfengjin committed Aug 6, 2021
1 parent 908899c commit 2ab6d4f
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions kernel/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package evm

import (
"encoding/hex"
"github.com/hyperledger/burrow/acm/balance"
"math/big"
"strconv"

//"github.com/hyperledger/burrow/acm/balance"
Expand Down Expand Up @@ -128,23 +130,53 @@ func (p *proxy) sendRawTransaction(ctx contract.KContext) (*contract.Response, e
); err != nil {
return nil, err
}
//from,err:=crypto.AddressFromBytes(rawt)
to, err := crypto.AddressFromBytes(rawTx.To)
if err != nil {
return nil, err
}

to, err := crypto.AddressFromHexString(string(rawTx.To))
enc, err := txs.RLPEncode(rawTx.Nonce, rawTx.GasPrice, rawTx.GasLimit, rawTx.To, rawTx.Value, rawTx.Data)
if err != nil {
return nil, err
}
contractName, err := DetermineContractNameFromEVM(to)

sig := crypto.CompressedSignatureFromParams(rawTx.V-net-8-1, rawTx.R, rawTx.S)
pub, err := crypto.PublicKeyFromSignature(sig, crypto.Keccak256(enc))
if err != nil {
return nil, err
}

args1 := map[string][]byte{
"input": rawTx.Data,
"jsonEncoded": []byte("false"),
if len(rawTx.Data) == 0 {
from := pub.GetAddress()
xfrom, err := EVMAddressToXchain(from)
if err != nil {
return nil, err
}
//to,err:=crypto
xto, err := EVMAddressToXchain(to)
if err != nil {
return nil, err
}
amount := balance.WeiToNative(rawTx.Value)
if err := ctx.Transfer(xfrom, xto, amount); err != nil {
return nil, err
}

} else {
contractName, err := DetermineContractNameFromEVM(to)
if err != nil {
return nil, err
}

args1 := map[string][]byte{
"input": rawTx.Data,
"jsonEncoded": []byte("false"),
}
resp, err := ctx.Call("evm", contractName, "", args1)
return resp, err
}
//TODO 如果value 非空,那么需要有 transfer
resp, err := ctx.Call("evm", contractName, "", args1)
return resp, err

}

func (p *proxy) ContractCall(ctx contract.KContext) (*contract.Response, error) {
Expand Down

0 comments on commit 2ab6d4f

Please sign in to comment.