-
Notifications
You must be signed in to change notification settings - Fork 12
/
checkpoint.go
83 lines (73 loc) · 2.33 KB
/
checkpoint.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
74
75
76
77
78
79
80
81
82
83
package types
import (
"math/big"
errorsmod "cosmossdk.io/errors"
"github.com/ethereum/go-ethereum/crypto"
"github.com/fbsobreira/gotron-sdk/pkg/abi"
fxtypes "github.com/functionx/fx-core/v5/types"
"github.com/functionx/fx-core/v5/x/crosschain/types"
)
// GetCheckpointOracleSet returns the checkpoint
func GetCheckpointOracleSet(oracleSet *types.OracleSet, gravityIDStr string) ([]byte, error) {
addresses := make([]string, len(oracleSet.Members))
powers := make([]*big.Int, len(oracleSet.Members))
for i, member := range oracleSet.Members {
addresses[i] = member.ExternalAddress
powers[i] = big.NewInt(int64(member.Power))
}
gravityID, err := fxtypes.StrToByte32(gravityIDStr)
if err != nil {
return nil, errorsmod.Wrap(err, "parse gravity id")
}
checkpoint, err := fxtypes.StrToByte32("checkpoint")
if err != nil {
return nil, errorsmod.Wrap(err, "parse checkpoint")
}
params := []abi.Param{
{"bytes32": gravityID},
{"bytes32": checkpoint},
{"uint256": big.NewInt(int64(oracleSet.Nonce))},
{"address[]": addresses},
{"uint256[]": powers},
}
encode, err := abi.GetPaddedParam(params)
if err != nil {
return nil, err
}
return crypto.Keccak256(encode), nil
}
func GetCheckpointConfirmBatch(txBatch *types.OutgoingTxBatch, gravityIDStr string) ([]byte, error) {
txCount := len(txBatch.Transactions)
amounts := make([]*big.Int, txCount)
destinations := make([]string, txCount)
fees := make([]*big.Int, txCount)
for i, transferTx := range txBatch.Transactions {
amounts[i] = transferTx.Token.Amount.BigInt()
destinations[i] = transferTx.DestAddress
fees[i] = transferTx.Fee.Amount.BigInt()
}
gravityID, err := fxtypes.StrToByte32(gravityIDStr)
if err != nil {
return nil, errorsmod.Wrap(err, "parse gravity id")
}
transactionBatch, err := fxtypes.StrToByte32("transactionBatch")
if err != nil {
return nil, errorsmod.Wrap(err, "parse checkpoint")
}
params := []abi.Param{
{"bytes32": gravityID},
{"bytes32": transactionBatch},
{"uint256[]": amounts},
{"address[]": destinations},
{"uint256[]": fees},
{"uint256": big.NewInt(int64(txBatch.BatchNonce))},
{"address": txBatch.TokenContract},
{"uint256": big.NewInt(int64(txBatch.BatchTimeout))},
{"address": txBatch.FeeReceive},
}
encode, err := abi.GetPaddedParam(params)
if err != nil {
return nil, err
}
return crypto.Keccak256(encode), nil
}