forked from zksync-sdk/zksync2-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transaction.go
60 lines (56 loc) · 1.63 KB
/
Transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package zksync2
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"math/big"
)
type Transaction struct {
From common.Address `json:"from"`
To common.Address `json:"to"`
Gas *hexutil.Big `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`
Data hexutil.Bytes `json:"data"`
//
Eip712Meta *Eip712Meta
}
func CreateFunctionCallTransaction(from, to common.Address, ergsPrice, ergsLimit, value *big.Int, data hexutil.Bytes,
customSignature hexutil.Bytes, paymasterParams *PaymasterParams) *Transaction {
return &Transaction{
From: from,
To: to,
Gas: (*hexutil.Big)(ergsLimit),
GasPrice: (*hexutil.Big)(ergsPrice),
Value: (*hexutil.Big)(value),
Data: data,
Eip712Meta: &Eip712Meta{
ErgsPerPubdata: NewBig(160000),
CustomSignature: customSignature,
FactoryDeps: nil,
PaymasterParams: paymasterParams,
},
}
}
func Create2ContractTransaction(from common.Address, ergsPrice, ergsLimit *big.Int,
bytecode, calldata hexutil.Bytes, deps []hexutil.Bytes,
customSignature hexutil.Bytes, paymasterParams *PaymasterParams) *Transaction {
if len(deps) > 0 {
deps = append(deps, bytecode)
} else {
deps = []hexutil.Bytes{bytecode}
}
return &Transaction{
From: from,
To: ContractDeployerAddress,
Gas: (*hexutil.Big)(ergsLimit),
GasPrice: (*hexutil.Big)(ergsPrice),
Value: nil,
Data: calldata,
Eip712Meta: &Eip712Meta{
ErgsPerPubdata: NewBig(160000),
CustomSignature: customSignature,
FactoryDeps: deps,
PaymasterParams: paymasterParams,
},
}
}