Skip to content

Commit 3077f9b

Browse files
author
chenfengjin
committed
Add transfer support
1 parent 908899c commit 3077f9b

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

kernel/evm/evm.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package evm
22

33
import (
44
"encoding/hex"
5+
"github.com/hyperledger/burrow/acm/balance"
56
"strconv"
67

78
//"github.com/hyperledger/burrow/acm/balance"
@@ -128,23 +129,55 @@ func (p *proxy) sendRawTransaction(ctx contract.KContext) (*contract.Response, e
128129
); err != nil {
129130
return nil, err
130131
}
132+
//from,err:=crypto.AddressFromBytes(rawt)
133+
to, err := crypto.AddressFromBytes(rawTx.To)
134+
if err != nil {
135+
return nil, err
136+
}
131137

132-
to, err := crypto.AddressFromHexString(string(rawTx.To))
138+
enc, err := txs.RLPEncode(rawTx.Nonce, rawTx.GasPrice, rawTx.GasLimit, rawTx.To, rawTx.Value, rawTx.Data)
133139
if err != nil {
134140
return nil, err
135141
}
142+
143+
sig := crypto.CompressedSignatureFromParams(rawTx.V-net-8-1, rawTx.R, rawTx.S)
144+
pub, err := crypto.PublicKeyFromSignature(sig, crypto.Keccak256(enc))
145+
if err != nil {
146+
return nil, err
147+
}
148+
149+
if len(rawTx.Data) == 0 {
150+
from := pub.GetAddress()
151+
xfrom, err := EVMAddressToXchain(from)
152+
if err != nil {
153+
return nil, err
154+
}
155+
xto, err := EVMAddressToXchain(to)
156+
if err != nil {
157+
return nil, err
158+
}
159+
amount := balance.WeiToNative(rawTx.Value)
160+
if err := ctx.Transfer(xfrom, xto, amount); err != nil {
161+
return nil, err
162+
}
163+
// TODO
164+
return &contract.Response{
165+
Status: 200,
166+
Body: []byte("TODO"),
167+
}, nil
168+
}
136169
contractName, err := DetermineContractNameFromEVM(to)
137170
if err != nil {
138171
return nil, err
139172
}
140173

141-
args1 := map[string][]byte{
174+
invokArgs := map[string][]byte{
142175
"input": rawTx.Data,
143176
"jsonEncoded": []byte("false"),
144177
}
145-
//TODO 如果value 非空,那么需要有 transfer
146-
resp, err := ctx.Call("evm", contractName, "", args1)
178+
resp, err := ctx.Call("evm", contractName, "", invokArgs)
147179
return resp, err
180+
148181
}
149182

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

0 commit comments

Comments
 (0)