utils

package
v0.0.0-...-1b15b10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2022 License: LGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGasLimit = 6721975
View Source
const DefaultGasPrice = 20000000000

Variables

View Source
var AdminRole = "0000000000000000000000000000000000000000000000000000000000000000"
View Source
var AliceKp = keystore.TestKeyRing.EthereumKeys[keystore.AliceKey]
View Source
var BobKp = keystore.TestKeyRing.EthereumKeys[keystore.BobKey]
View Source
var (
	DefaultRelayerAddresses = []common.Address{
		common.HexToAddress(keystore.TestKeyRing.EthereumKeys[keystore.AliceKey].Address()),
		common.HexToAddress(keystore.TestKeyRing.EthereumKeys[keystore.BobKey].Address()),
		common.HexToAddress(keystore.TestKeyRing.EthereumKeys[keystore.CharlieKey].Address()),
		common.HexToAddress(keystore.TestKeyRing.EthereumKeys[keystore.DaveKey].Address()),
		common.HexToAddress(keystore.TestKeyRing.EthereumKeys[keystore.EveKey].Address()),
	}
)
View Source
var EveKp = keystore.TestKeyRing.EthereumKeys[keystore.EveKey]
View Source
var ExpectedBlockTime = 2 * time.Second

Functions

func AdminAddAdmin

func AdminAddAdmin(client *client.Client, bridge common.Address, newAdmin common.Address) error

func AdminAddRelyaer

func AdminAddRelyaer(client *client.Client, bridge common.Address, relayer common.Address) error

func AdminFeeAmount

func AdminFeeAmount(client *client.Client, bridge common.Address) (*big.Int, error)

func AdminIsRelayer

func AdminIsRelayer(client *client.Client, bridge common.Address, relayer common.Address) (bool, error)

func AdminPause

func AdminPause(client *client.Client, bridge common.Address) error

func AdminRemoveAdmin

func AdminRemoveAdmin(client *client.Client, bridge common.Address, addresToRevoke common.Address) error

func AdminRemoveRelayer

func AdminRemoveRelayer(client *client.Client, bridge common.Address, relayer common.Address) error

func AdminSetFee

func AdminSetFee(client *client.Client, bridge common.Address, newFee *big.Int) error

func AdminSetThreshHold

func AdminSetThreshHold(client *client.Client, bridge common.Address, treshHold *big.Int) error

func AdminUnpause

func AdminUnpause(client *client.Client, bridge common.Address) error

func AdminWithdraw

func AdminWithdraw(client *client.Client, bridge, handler, token, recipient common.Address, amount *big.Int) error

func BridgeDeposit

func BridgeDeposit(client *client.Client, bridge common.Address, destChainID uint8, resourceID [32]byte, data []byte) error

func BuildQuery

func BuildQuery(contract common.Address, sig EventSig, startBlock *big.Int, endBlock *big.Int) ethereum.FilterQuery

func CancelProposal

func CancelProposal(client *client.Client, bridgeAddress common.Address, chainID uint8, depositNonce uint64, dataHash [32]byte) error

func ConstructErc20DepositData

func ConstructErc20DepositData(destRecipient []byte, amount *big.Int) []byte

func ConstructErc721DepositData

func ConstructErc721DepositData(tokenId *big.Int, destRecipient []byte) []byte

constructErc20Data constructs the data field to be passed into an erc721 deposit call

func ConstructGenericDepositData

func ConstructGenericDepositData(metadata []byte) []byte

func DeployBridge

func DeployBridge(client *client.Client, chainID uint8, relayerAddrs []common.Address, initialRelayerThreshold *big.Int, fee *big.Int) (common.Address, error)

func DeployERC20Handler

func DeployERC20Handler(client *client.Client, bridgeAddress common.Address) (common.Address, error)

func DeployERC20Token

func DeployERC20Token(client *client.Client, name, symbol string) (common.Address, error)

func DeployERC721Handler

func DeployERC721Handler(client *client.Client, bridgeAddress common.Address) (common.Address, error)

func DeployERC721Token

func DeployERC721Token(client *client.Client) (common.Address, error)

func DeployGenericHandler

func DeployGenericHandler(client *client.Client, bridgeAddress common.Address) (common.Address, error)

func ERC20AddMinter

func ERC20AddMinter(client *client.Client, erc20Address, minter common.Address) error

func ERC20Allowance

func ERC20Allowance(client *client.Client, erc20Address, spender, owner common.Address) (*big.Int, error)

func ERC20Approve

func ERC20Approve(client *client.Client, erc20Address, spender common.Address, amount *big.Int) error

func ERC20BalanceOf

func ERC20BalanceOf(client *client.Client, erc20Address, dest common.Address) (*big.Int, error)

func ERC20IsMinter

func ERC20IsMinter(client *client.Client, erc20Address, minter common.Address) (bool, error)

func ERC20Mint

func ERC20Mint(client *client.Client, amount *big.Int, erc20Address, recipient common.Address) error

func ERC20MinterRole

func ERC20MinterRole(client *client.Client, erc20Address common.Address) ([32]byte, error)

func ERC20Transfer

func ERC20Transfer(client *client.Client, erc20 *erc20.ERC20PresetMinterPauser, recipient common.Address, amount *big.Int) (*types.Transaction, error)

nolint

func ERC721AddMinter

func ERC721AddMinter(client *client.Client, erc721Address, minter common.Address) error

func ERC721Approve

func ERC721Approve(client *client.Client, erc721Address, recipient common.Address, id *big.Int) error

func ERC721Mint

func ERC721Mint(client *client.Client, erc721Address, to common.Address, id *big.Int, metadata string) error

func ERC721MinterRole

func ERC721MinterRole(client *client.Client, erc721Address common.Address) ([32]byte, error)

func ERC721OwnerOf

func ERC721OwnerOf(client *client.Client, erc721Address common.Address, id *big.Int) (common.Address, error)

func Erc20AddMinter

func Erc20AddMinter(client *client.Client, erc20Contract, handler common.Address) error

func Erc20Approve

func Erc20Approve(client *client.Client, erc20Contract, target common.Address, amount *big.Int) error

func GetSolidityFunctionSig

func GetSolidityFunctionSig(in string) [4]byte

func IsActive

func IsActive(status uint8) bool

func IsExecuted

func IsExecuted(status uint8) bool

func IsPassed

func IsPassed(status uint8) bool

func MakeAndSendERC20Deposit

func MakeAndSendERC20Deposit(client *client.Client, bridgeAddress common.Address, recipient common.Address, amount *big.Int, resourceID [32]byte, destChainID uint8) error

func MakeAndSendERC721Deposit

func MakeAndSendERC721Deposit(client *client.Client, bridgeAddress common.Address, recipient common.Address, id *big.Int, resourceID [32]byte, destChainID uint8) error

func MakeErc20Deposit

func MakeErc20Deposit(client *client.Client, bridgeAddress common.Address, recipient common.Address, amount *big.Int, resourceID [32]byte, destChainID uint8) (*types.Transaction, error)

func MintTokens

func MintTokens(client *client.Client, erc20Addr common.Address, amount *big.Int) error

func QueryProposal

func QueryProposal(client *client.Client, bridgeAddress common.Address, chainID uint8, depositNonce uint64, dataHash [32]byte) (*Bridge.BridgeProposal, error)

func QueryResource

func QueryResource(client *client.Client, handler common.Address, resourceID [32]byte) (common.Address, error)

func RegisterGenericResource

func RegisterGenericResource(client *client.Client, bridge, handler common.Address, rId msg.ResourceId, addr common.Address, depositSig, executeSig [4]byte) error

func RegisterResource

func RegisterResource(client *client.Client, bridge, handler common.Address, rId [32]byte, addr common.Address) error

func RlpEncodeHeader

func RlpEncodeHeader(header *types.Header) ([]byte, error)

RlpEncodeHeader is method to RLP encode data stored in a block header

func SetBurnable

func SetBurnable(client *client.Client, bridge, handler, contract common.Address) error

func Simulate

func Simulate(client *client.Client, block *big.Int, txHash common.Hash, from common.Address) ([]byte, error)

Simulate function gets transaction info by hash and then executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain. Execution happens against provided block.

func SliceTo32Bytes

func SliceTo32Bytes(in []byte) [32]byte

func SliceTo4Bytes

func SliceTo4Bytes(in []byte) [4]byte

func UserAmountToWei

func UserAmountToWei(amount string, decimal *big.Int) (*big.Int, error)

UserAmountToWei converts decimal user friendly representation of token amount to 'Wei' representation with provided amount of decimal places eg UserAmountToWei(1, 5) => 100000

func WaitAndReturnTxReceipt

func WaitAndReturnTxReceipt(client *client.Client, tx *types.Transaction) (*types.Receipt, error)

WaitForTx will query the chain at ExpectedBlockTime intervals, until a receipt is returned. Returns an error if the tx failed.

func WaitForTx

func WaitForTx(client *client.Client, tx *types.Transaction) error

WaitForTx will query the chain at ExpectedBlockTime intervals, until a receipt is returned. Returns an error if the tx failed.

func WeiAmountToUser

func WeiAmountToUser(amount *big.Int, decimals *big.Int) (*big.Float, error)

Types

type ChainId

type ChainId uint8

type DeployedContracts

type DeployedContracts struct {
	BridgeAddress         common.Address
	ERC20HandlerAddress   common.Address
	ERC721HandlerAddress  common.Address
	GenericHandlerAddress common.Address
	ERC20TokenAddress     common.Address
}

func DeployContracts

func DeployContracts(client *client.Client, chainID uint8, initialRelayerThreshold *big.Int, relayerAddresses []common.Address, erc20Name, erc20Symbol string, bridgeFee *big.Int) (*DeployedContracts, error)

DeployContracts deploys Bridge, Relayer, ERC20Handler, ERC721Handler and CentrifugeAssetHandler and returns the addresses

type EventSig

type EventSig string
const (
	Deposit       EventSig = "Deposit(uint8,bytes32,uint64)"
	ProposalEvent EventSig = "ProposalEvent(uint8,uint64,uint8,bytes32,bytes32)"
)

func (EventSig) GetTopic

func (es EventSig) GetTopic() common.Hash

type MerkleProof

type MerkleProof struct {
	TxRootHash [32]byte // Expected root of trie, in our case should be transactionsRoot from block
	Key        []byte   // RLP encoding of tx index, for the tx we want to prove
	Nodes      []byte   // The actual proof, all the nodes of the trie that between leaf value and root
}

type Message

type Message struct {
	Source       ChainId      // Source where message was initiated
	Destination  ChainId      // Destination chain of message
	Type         TransferType // type of bridge transfer
	DepositNonce Nonce        // Nonce for the deposit
	ResourceId   ResourceId
	MPParams     *MerkleProof
	SVParams     *SignatureVerification
	Payload      []interface{} // data associated with event sequence
}

Message is used as a generic format to communicate between chains

func NewFungibleTransfer

func NewFungibleTransfer(source, dest ChainId, nonce Nonce, resourceId ResourceId, mp *MerkleProof, sv *SignatureVerification, amount *big.Int, recipient []byte) *Message

func NewGenericTransfer

func NewGenericTransfer(source, dest ChainId, nonce Nonce, resourceId ResourceId, mp *MerkleProof, sv *SignatureVerification, metadata []byte) *Message

func NewNonFungibleTransfer

func NewNonFungibleTransfer(source, dest ChainId, nonce Nonce, resourceId ResourceId, mp *MerkleProof, sv *SignatureVerification, tokenId *big.Int, recipient, metadata []byte) *Message

type Nonce

type Nonce uint64

func (Nonce) Big

func (n Nonce) Big() *big.Int

type ProposalStatus

type ProposalStatus int
const (
	Inactive ProposalStatus = iota
	Active
	Passed
	Executed
	Cancelled
)

type ResourceId

type ResourceId [32]byte

func (*ResourceId) Hex

func (r *ResourceId) Hex() string

type SignatureVerification

type SignatureVerification struct {
	AggregatePublicKey []byte      // Aggregated public key of block validators
	BlockHash          common.Hash // Hash of block we are proving
	Signature          []byte      // Signature of block we are proving
	RLPHeader          []byte      // RLP encoding of header data
}

type TransferType

type TransferType string
var FungibleTransfer TransferType = "FungibleTransfer"
var GenericTransfer TransferType = "GenericTransfer"
var NonFungibleTransfer TransferType = "NonFungibleTransfer"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL