-
Notifications
You must be signed in to change notification settings - Fork 1
/
transactions.go
73 lines (59 loc) · 1.8 KB
/
transactions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
// Package transactions is used to build transaction objects.
// these objects will be used to build the final rpc call to the node.
package transactions
import (
"math/big"
"github.com/eyeonicon/go-icon-sdk/networks"
"github.com/eyeonicon/go-icon-sdk/util"
"github.com/icon-project/goloop/module"
"github.com/icon-project/goloop/server/jsonrpc"
"github.com/icon-project/goloop/server/v3"
)
// CallBuilder builds and returns a object that will be send to the network
func CallBuilder(to string, method string, params interface{}) *v3.CallParam {
// convert to to jsonrpc.Address
toAddress := jsonrpc.Address(to)
// build data
data := map[string]interface{}{
"method": method,
}
if params != nil {
data["params"] = params
}
callParams := v3.CallParam{
FromAddress: "hx0000000000000000000000000000000000000000",
ToAddress: toAddress,
DataType: "call",
Data: data,
// Value: util.BigIntToHex(amount),
}
return &callParams
}
// TransactionBuilder builds and returns an object that will be signed using the
// loaded wallet and send to the network
func TransactionBuilder(from module.Address, to string, method string, params interface{}, value *big.Int) *v3.TransactionParam {
// convert to to jsonrpc.Address
toAddress := jsonrpc.Address(to)
// convert from to jsonrpc.Address
fromAddress := jsonrpc.Address(from.String())
// build data object
data := map[string]interface{}{
"method": method,
}
if params != nil {
data["params"] = params
}
txParams := v3.TransactionParam{
FromAddress: fromAddress,
ToAddress: toAddress,
Value: util.BigIntToHex(value),
StepLimit: "0xf4240",
NetworkID: networks.GetActiveNetwork().NID,
Nonce: "0x1",
Version: "0x3",
Timestamp: "0x",
DataType: "call",
Data: data,
}
return &txParams
}