Categorygithub.com/bitmark-inc/account-vault-ethereum
modulepackage
0.6.11
Repository: https://github.com/bitmark-inc/account-vault-ethereum.git
Documentation: pkg.go.dev

# README

Account Vault Ethereum

The goal of this package is to enable bitmark account vault supporting Ethereum.

This package includes:

  • An ethereum wallet
  • A contract interface which defines how account vault interact with smart contracts
  • A singleton for contract registration

Wrap a contract

With the contract ABI file, we can generate a contract module through abigen. By creating a wrapper structure which implements the Call and Deploy function, a client can interact with all the different contract in the same interfaces.

The Call function determines which method could be exposed and how a client is going to invoke it. Whereas the Deploy function is obviously for deploying a new contract.

Here is a simple example of wrapping a contract:

type TestContract struct {
	contractAddress string
}

// Deploy deploys the smart contract to ethereum blockchain
func (c *TestContract) Deploy(wallet *ethereum.Wallet, arguments json.RawMessage) (string, string, error) {
	t, err := wallet.Transactor()
	if err != nil {
		return "", "", err
	}

	address, tx, _, err := DeployTestContract(t, wallet.RPCClient())
	if err != nil {
		return "", "", err
	}
	return address.String(), tx.Hash().String(), nil
}

// Call is the entry function for account vault to interact with a smart contract.
func (c *TestContract) Call(wallet *ethereum.Wallet, method, fund string, arguments json.RawMessage) (string, error) {
	contract, err := NewTestContract(common.HexToAddress(c.contractAddress), wallet.RPCClient())
	if err != nil {
		return "", err
	}

	t, err := wallet.Transactor()
	if err != nil {
		return "", err
	}

	switch method {
	case "set_tester":
		var params struct {
		    Tester common.Address `json:"tester"`
		}
		if err := json.Unmarshal(arguments, &params); err != nil {
			return "", err
		}

		tx, err := contract.CreateArtwork(t, params.Tester)
		if err != nil {
			return "", err
		}
		return tx.Hash().String(), err
	default:
		return "", fmt.Errorf("unsupported method")
	}
}

Register contracts

To simply the contract importing, the package creates a sigleton of registered contracts. Each wrapped contract needs to create a factory function which takes an address as parameter and returns the instance of it. For example,

func TestContractFactory(contractAddress string) ethereum.Contract {
	return &TestContract{
		contractAddress: contractAddress,
	}
}

For each contract modules, it registers itself using the RegisterContract call. For example,

func init() {
	ethereum.RegisterContract("TestContract", TestContractFactory)
}

A client can easily query contracts by using GetContract function.

Build abi.go

Required package

  • truffle
  • jq
  • abigen
  • npm
  • make

Scripts

make build

# Packages

No description provided by the author

# Functions

GetContract returns.
NewERC20Token creates a new instance of ERC20Token, bound to a specific deployed contract.
NewERC20TokenCaller creates a new read-only instance of ERC20Token, bound to a specific deployed contract.
NewERC20TokenFilterer creates a new log filterer instance of ERC20Token, bound to a specific deployed contract.
NewERC20TokenTransactor creates a new write-only instance of ERC20Token, bound to a specific deployed contract.
NewTokenBatchTransfer creates a new instance of TokenBatchTransfer, bound to a specific deployed contract.
NewTokenBatchTransferCaller creates a new read-only instance of TokenBatchTransfer, bound to a specific deployed contract.
NewTokenBatchTransferFilterer creates a new log filterer instance of TokenBatchTransfer, bound to a specific deployed contract.
NewTokenBatchTransferTransactor creates a new write-only instance of TokenBatchTransfer, bound to a specific deployed contract.
NewWallet creates a wallet from a given seed.
NewWallet creates a wallet from a given mnemonic phrases.
RegisterContract registers a contract.
WeiToEther converts wei into eth.

# Constants

ABI_TUPLE_KEY_ORDER is a specific key that should be defined in tuple structure definition.
No description provided by the author

# Variables

ERC20TokenABI is the input ABI used to generate the binding from.
ERC20TokenMetaData contains all meta data concerning the ERC20Token contract.
TokenBatchTransferABI is the input ABI used to generate the binding from.
TokenBatchTransferMetaData contains all meta data concerning the TokenBatchTransfer contract.

# Structs

No description provided by the author
ERC20Token is an auto generated Go binding around an Ethereum contract.
ERC20TokenApproval represents a Approval event raised by the ERC20Token contract.
ERC20TokenApprovalIterator is returned from FilterApproval and is used to iterate over the raw logs and unpacked data for Approval events raised by the ERC20Token contract.
ERC20TokenAuthorizationCanceled represents a AuthorizationCanceled event raised by the ERC20Token contract.
ERC20TokenAuthorizationCanceledIterator is returned from FilterAuthorizationCanceled and is used to iterate over the raw logs and unpacked data for AuthorizationCanceled events raised by the ERC20Token contract.
ERC20TokenAuthorizationUsed represents a AuthorizationUsed event raised by the ERC20Token contract.
ERC20TokenAuthorizationUsedIterator is returned from FilterAuthorizationUsed and is used to iterate over the raw logs and unpacked data for AuthorizationUsed events raised by the ERC20Token contract.
ERC20TokenBlacklisted represents a Blacklisted event raised by the ERC20Token contract.
ERC20TokenBlacklistedIterator is returned from FilterBlacklisted and is used to iterate over the raw logs and unpacked data for Blacklisted events raised by the ERC20Token contract.
ERC20TokenBlacklisterChanged represents a BlacklisterChanged event raised by the ERC20Token contract.
ERC20TokenBlacklisterChangedIterator is returned from FilterBlacklisterChanged and is used to iterate over the raw logs and unpacked data for BlacklisterChanged events raised by the ERC20Token contract.
ERC20TokenBurn represents a Burn event raised by the ERC20Token contract.
ERC20TokenBurnIterator is returned from FilterBurn and is used to iterate over the raw logs and unpacked data for Burn events raised by the ERC20Token contract.
ERC20TokenCaller is an auto generated read-only Go binding around an Ethereum contract.
ERC20TokenCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
ERC20TokenCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.
ERC20TokenFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
ERC20TokenMasterMinterChanged represents a MasterMinterChanged event raised by the ERC20Token contract.
ERC20TokenMasterMinterChangedIterator is returned from FilterMasterMinterChanged and is used to iterate over the raw logs and unpacked data for MasterMinterChanged events raised by the ERC20Token contract.
ERC20TokenMint represents a Mint event raised by the ERC20Token contract.
ERC20TokenMinterConfigured represents a MinterConfigured event raised by the ERC20Token contract.
ERC20TokenMinterConfiguredIterator is returned from FilterMinterConfigured and is used to iterate over the raw logs and unpacked data for MinterConfigured events raised by the ERC20Token contract.
ERC20TokenMinterRemoved represents a MinterRemoved event raised by the ERC20Token contract.
ERC20TokenMinterRemovedIterator is returned from FilterMinterRemoved and is used to iterate over the raw logs and unpacked data for MinterRemoved events raised by the ERC20Token contract.
ERC20TokenMintIterator is returned from FilterMint and is used to iterate over the raw logs and unpacked data for Mint events raised by the ERC20Token contract.
ERC20TokenOwnershipTransferred represents a OwnershipTransferred event raised by the ERC20Token contract.
ERC20TokenOwnershipTransferredIterator is returned from FilterOwnershipTransferred and is used to iterate over the raw logs and unpacked data for OwnershipTransferred events raised by the ERC20Token contract.
ERC20TokenPause represents a Pause event raised by the ERC20Token contract.
ERC20TokenPauseIterator is returned from FilterPause and is used to iterate over the raw logs and unpacked data for Pause events raised by the ERC20Token contract.
ERC20TokenPauserChanged represents a PauserChanged event raised by the ERC20Token contract.
ERC20TokenPauserChangedIterator is returned from FilterPauserChanged and is used to iterate over the raw logs and unpacked data for PauserChanged events raised by the ERC20Token contract.
ERC20TokenRaw is an auto generated low-level Go binding around an Ethereum contract.
ERC20TokenRescuerChanged represents a RescuerChanged event raised by the ERC20Token contract.
ERC20TokenRescuerChangedIterator is returned from FilterRescuerChanged and is used to iterate over the raw logs and unpacked data for RescuerChanged events raised by the ERC20Token contract.
ERC20TokenSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.
ERC20TokenTransactor is an auto generated write-only Go binding around an Ethereum contract.
ERC20TokenTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
ERC20TokenTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.
ERC20TokenTransfer represents a Transfer event raised by the ERC20Token contract.
ERC20TokenTransferIterator is returned from FilterTransfer and is used to iterate over the raw logs and unpacked data for Transfer events raised by the ERC20Token contract.
ERC20TokenUnBlacklisted represents a UnBlacklisted event raised by the ERC20Token contract.
ERC20TokenUnBlacklistedIterator is returned from FilterUnBlacklisted and is used to iterate over the raw logs and unpacked data for UnBlacklisted events raised by the ERC20Token contract.
ERC20TokenUnpause represents a Unpause event raised by the ERC20Token contract.
ERC20TokenUnpauseIterator is returned from FilterUnpause and is used to iterate over the raw logs and unpacked data for Unpause events raised by the ERC20Token contract.
TokenBatchTransfer is an auto generated Go binding around an Ethereum contract.
TokenBatchTransferCaller is an auto generated read-only Go binding around an Ethereum contract.
TokenBatchTransferCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
TokenBatchTransferCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.
TokenBatchTransferFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
TokenBatchTransferNewOperator represents a NewOperator event raised by the TokenBatchTransfer contract.
TokenBatchTransferNewOperatorIterator is returned from FilterNewOperator and is used to iterate over the raw logs and unpacked data for NewOperator events raised by the TokenBatchTransfer contract.
TokenBatchTransferOwnershipTransferred represents a OwnershipTransferred event raised by the TokenBatchTransfer contract.
TokenBatchTransferOwnershipTransferredIterator is returned from FilterOwnershipTransferred and is used to iterate over the raw logs and unpacked data for OwnershipTransferred events raised by the TokenBatchTransfer contract.
TokenBatchTransferRaw is an auto generated low-level Go binding around an Ethereum contract.
TokenBatchTransferSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.
TokenBatchTransferTransactor is an auto generated write-only Go binding around an Ethereum contract.
TokenBatchTransferTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
TokenBatchTransferTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.
TokenBatchTransferWithdrawToken represents a WithdrawToken event raised by the TokenBatchTransfer contract.
TokenBatchTransferWithdrawTokenIterator is returned from FilterWithdrawToken and is used to iterate over the raw logs and unpacked data for WithdrawToken events raised by the TokenBatchTransfer contract.
No description provided by the author

# Interfaces

Contract is an interface defines how a vault interact with the smart contract.

# Type aliases

ContractFactory is a function that takes an address and return a Contract instance.