-
Notifications
You must be signed in to change notification settings - Fork 0
/
deposit.go
37 lines (29 loc) · 1.26 KB
/
deposit.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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package utils
import (
"math/big"
"github.com/ethereum/go-ethereum/common/math"
)
// constructErc20Data constructs the data field to be passed into a n erc20 deposit call
func ConstructErc20DepositData(destRecipient []byte, amount *big.Int) []byte {
var data []byte
data = append(data, math.PaddedBigBytes(amount, 32)...)
data = append(data, math.PaddedBigBytes(big.NewInt(int64(len(destRecipient))), 32)...)
data = append(data, destRecipient...)
return data
}
// constructErc20Data constructs the data field to be passed into an erc721 deposit call
func ConstructErc721DepositData(tokenId *big.Int, destRecipient []byte) []byte {
var data []byte
data = append(data, math.PaddedBigBytes(tokenId, 32)...) // Resource Id + Token Id
data = append(data, math.PaddedBigBytes(big.NewInt(int64(len(destRecipient))), 32)...) // Length of recipient
data = append(data, destRecipient...) // Recipient
return data
}
func ConstructGenericDepositData(metadata []byte) []byte {
var data []byte
data = append(data, math.PaddedBigBytes(big.NewInt(int64(len(metadata))), 32)...)
data = append(data, metadata...)
return data
}