-
Notifications
You must be signed in to change notification settings - Fork 39
/
erc20_contract_lib.go
40 lines (31 loc) · 1.08 KB
/
erc20_contract_lib.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
package ethereummock
import (
"bytes"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/ethadapter/erc20contractlib"
gethcommon "github.com/ethereum/go-ethereum/common"
)
type contractLib struct{}
func (c *contractLib) CreateDepositTx(tx *common.L1DepositTx) types.TxData {
return encodeTx(tx, depositTxAddr)
}
// DecodeTx - return only deposit transactions to the management contract
func (c *contractLib) DecodeTx(tx *types.Transaction) common.TenTransaction {
if bytes.Equal(tx.To().Bytes(), depositTxAddr.Bytes()) {
depositTx, ok := decodeTx(tx).(*common.L1DepositTx)
if !ok {
return nil
}
// Mock deposits towards the L1 bridge target nil as the management contract address
// is not set.
if bytes.Equal(depositTx.To.Bytes(), gethcommon.BigToAddress(gethcommon.Big0).Bytes()) {
return depositTx
}
}
return nil
}
// NewERC20ContractLibMock is an implementation of the erc20contractlib.ERC20ContractLib
func NewERC20ContractLibMock() erc20contractlib.ERC20ContractLib {
return &contractLib{}
}