zcnbridge

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 43 Imported by: 3

README

Implementation

Required

  1. Transaction entity to create transaction
  2. HTTP Client setup to make requests to the chain (miners and sharders)
  3. Wallet setup to be able to register in the chain to sign transaction

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultClientIDEncoder = func(id string) []byte {
		return []byte(id)
	}
)

Functions

func ConfirmEthereumTransaction

func ConfirmEthereumTransaction(hash string, times int, duration time.Duration) (int, error)

func ExitWithError added in v1.3.2

func ExitWithError(v ...interface{})

func GetTransactionStatus

func GetTransactionStatus(hash string) (int, error)

func InitChainFromConfig added in v1.3.2

func InitChainFromConfig(reader conf.Reader)

func ReadConfig added in v1.3.2

func ReadConfig(configPath, configName string)

func RestoreFromConfig added in v1.3.2

func RestoreFromConfig(cfg *conf.Config)

Types

type Authorizer

type Authorizer struct {
}

type AuthorizerNode

type AuthorizerNode struct {
	ID        string `json:"id"`
	PublicKey string `json:"public_key"`
	URL       string `json:"url"`
}

type AuthorizerNodes

type AuthorizerNodes struct {
	NodeMap map[string]*AuthorizerNode `json:"node_map"`
}

func GetAuthorizers

func GetAuthorizers() (*AuthorizerNodes, error)

GetAuthorizers Returns authorizers

type Bridge

type Bridge struct {
	*BridgeConfig
	*Instance
}

func SetupBridge added in v1.3.2

func SetupBridge(configDir, configFile string, development bool, logPath string) *Bridge

SetupBridge Use this from standalone application

func SetupBridgeFromConfig

func SetupBridgeFromConfig() *Bridge

func (*Bridge) BurnWZCN

func (b *Bridge) BurnWZCN(ctx context.Context, amountTokens int64) (*types.Transaction, error)

BurnWZCN Burns WZCN tokens on behalf of the 0ZCN client amountTokens - ZCN tokens clientID - 0ZCN client ERC20 signature: "burn(uint256,bytes)"

func (*Bridge) BurnZCN

func (b *Bridge) BurnZCN(ctx context.Context) (*transaction.Transaction, error)

func (*Bridge) CreateEthClient

func (b *Bridge) CreateEthClient() (*ethclient.Client, error)

func (*Bridge) CreateEthereumWallet added in v1.3.2

func (b *Bridge) CreateEthereumWallet() (*EthereumWallet, error)

func (*Bridge) CreateSignedTransaction

func (b *Bridge) CreateSignedTransaction(
	chainID *big.Int,
	client *ethclient.Client,
	fromAddress common.Address,
	privateKey *ecdsa.PrivateKey,
	gasLimitUnits uint64,
) *bind.TransactOpts

func (*Bridge) GetEthereumAddress

func (b *Bridge) GetEthereumAddress() ether.Address

GetEthereumAddress returns ethereum wallet string

func (*Bridge) GetEthereumWallet

func (b *Bridge) GetEthereumWallet() *EthereumWallet

GetEthereumWallet returns ethereum wallet string

func (*Bridge) GetEthereumWalletInfo

func (b *Bridge) GetEthereumWalletInfo() (*EthWalletInfo, error)

func (*Bridge) GetKeysAddress

func (b *Bridge) GetKeysAddress() (common.Address, *ecdsa.PublicKey, *ecdsa.PrivateKey, error)

func (*Bridge) ID

func (b *Bridge) ID() string

ID returns id of Node.

func (*Bridge) IncreaseBurnerAllowance

func (b *Bridge) IncreaseBurnerAllowance(ctx context.Context, amountWei wei) (*types.Transaction, error)

IncreaseBurnerAllowance Increases allowance for bridge contract address to transfer WZCN tokens on behalf of the token owner to the Burn TokenPool During the burn the script transfers amount from token owner to the bridge burn token pool Example: owner wants to burn some amount. The contract will transfer some amount from owner address to the pool. So the owner must call IncreaseAllowance of the WZCN token with 2 parameters: spender address which is the bridge contract and amount to be burned (transferred) ERC20 signature: "increaseAllowance(address,uint256)"

func (*Bridge) IncrementNonce

func (b *Bridge) IncrementNonce() int64

func (*Bridge) MintWZCN

func (b *Bridge) MintWZCN(ctx context.Context, amountTokens wei, payload *ethereum.MintPayload) (*types.Transaction, error)

MintWZCN Mint ZCN tokens on behalf of the 0ZCN client amountTokens: ZCN tokens payload: received from authorizers

func (*Bridge) MintZCN

func (b *Bridge) MintZCN(ctx context.Context, payload *zcnsc.MintPayload) (*transaction.Transaction, error)

func (*Bridge) QueryEthereumMintPayload

func (b *Bridge) QueryEthereumMintPayload(zchainBurnHash string) (*ethereum.MintPayload, error)

QueryEthereumMintPayload gets burn ticket and creates mint payload to be minted in the Ethereum chain zchainBurnHash - Ethereum burn transaction hash

func (*Bridge) QueryZChainMintPayload

func (b *Bridge) QueryZChainMintPayload(ethBurnHash string) (*zcnsc.MintPayload, error)

QueryZChainMintPayload gets burn ticket and creates mint payload to be minted in the ZChain ethBurnHash - Ethereum burn transaction hash

func (*Bridge) RestoreChain added in v1.3.2

func (b *Bridge) RestoreChain()

func (*Bridge) SetupChain added in v1.3.2

func (b *Bridge) SetupChain()

func (*Bridge) SetupEthereumWallet

func (b *Bridge) SetupEthereumWallet()

func (*Bridge) SetupSDK

func (b *Bridge) SetupSDK(cfg chain.Config)

func (*Bridge) SetupWallet added in v1.3.2

func (b *Bridge) SetupWallet()

SetupWallet Sets up the wallet and node Wallet setup reads keys from keyfile and registers in the 0chain

type BridgeConfig

type BridgeConfig struct {
	// Ethereum mnemonic (derivation of Ethereum owner, public and private key)
	Mnemonic string
	// Address of Ethereum bridge contract
	BridgeAddress string
	// Address of WZCN Ethereum wrapped token
	WzcnAddress string
	// URL of ethereum RPC node (infura or alchemy)
	EthereumNodeURL string
	// Ethereum chain ID
	ChainID string
	// Gas limit to execute ethereum transaction
	GasLimit uint64
	// Value to execute ZCN smart contracts
	Value int64
	// Authorizers required to confirm (in percents)
	ConsensusThreshold int
}

BridgeConfig initializes Ethereum wallet and params

type ClientConfig

type ClientConfig struct {
	LogPath     *string
	ConfigFile  *string
	ConfigDir   *string
	Development *bool
}

func ReadClientConfigFromCmd

func ReadClientConfigFromCmd() *ClientConfig

ReadClientConfigFromCmd reads config from command line

func (ClientConfig) BlockWorker

func (c ClientConfig) BlockWorker() string

func (ClientConfig) LogDir

func (c ClientConfig) LogDir() string

func (ClientConfig) LogLvl

func (c ClientConfig) LogLvl() string

func (ClientConfig) SignatureScheme

func (c ClientConfig) SignatureScheme() string

type EthWalletInfo

type EthWalletInfo struct {
	ID         string `json:"ID"`
	PrivateKey string `json:"PrivateKey"`
}

type EthereumWallet

type EthereumWallet struct {
	PublicKey  *ecdsa.PublicKey
	PrivateKey *ecdsa.PrivateKey
	Address    common.Address
}

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

type JobError

type JobError struct {
	// contains filtered or unexported fields
}

JobError result of internal request wrapped in authorizer job

func (*JobError) MarshalJSON

func (e *JobError) MarshalJSON() ([]byte, error)

func (*JobError) UnmarshalJSON

func (e *JobError) UnmarshalJSON(buf []byte) error

type JobResult

type JobResult interface {
	// Error = Status of Authorizer job
	Error() error
	// Data returns the actual result
	Data() interface{}
	// SetAuthorizerID Assigns authorizer ID to the Job
	SetAuthorizerID(ID string)
	// GetAuthorizerID returns authorizer ID
	GetAuthorizerID() string
}

JobResult = Authorizer task result, it wraps actual result of the query inside authorizer

type JobStatus

type JobStatus uint

JobStatus = Ethereum transaction status

type ProofEthereumBurn

type ProofEthereumBurn struct {
	TxnID             string `json:"ethereum_txn_id"`
	Nonce             int64  `json:"nonce"`
	Amount            int64  `json:"amount"`
	ReceivingClientID string `json:"receiving_client_id"` // 0ZCN address
	Signature         string `json:"signature"`
}

ProofEthereumBurn Authorizer returns this type for Ethereum transaction

type ProofZCNBurn

type ProofZCNBurn struct {
	AuthorizerID    string `json:"authorizer_id,omitempty"`
	TxnID           string `json:"0chain_txn_id"`
	Nonce           int64  `json:"nonce"`
	Amount          int64  `json:"amount"`
	EthereumAddress string `json:"ethereum_address"`
	Signature       string `json:"signatures"`
}

ProofZCNBurn Authorizer returns this type for ZCN transaction

func (*ProofZCNBurn) Data

func (r *ProofZCNBurn) Data() interface{}

func (*ProofZCNBurn) Error

func (r *ProofZCNBurn) Error() error

func (*ProofZCNBurn) GetAuthorizerID

func (r *ProofZCNBurn) GetAuthorizerID() string

func (*ProofZCNBurn) SetAuthorizerID

func (r *ProofZCNBurn) SetAuthorizerID(id string)

type WZCNBurnEvent

type WZCNBurnEvent struct {
	// 	AuthorizerID Authorizer ID
	AuthorizerID string `json:"authorizer_id,omitempty"`
	// BurnTicket Returns burn ticket
	BurnTicket *ProofEthereumBurn `json:"ticket,omitempty"`
	// Err gives error of job on server side
	Err *JobError `json:"err,omitempty"`
	// Status gives job status on server side (authoriser)
	Status JobStatus `json:"status,omitempty"`
}

WZCNBurnEvent returned from burn ticket handler of: /v1/ether/burnticket/get

func (*WZCNBurnEvent) Data

func (r *WZCNBurnEvent) Data() interface{}

func (*WZCNBurnEvent) Error

func (r *WZCNBurnEvent) Error() error

func (*WZCNBurnEvent) GetAuthorizerID

func (r *WZCNBurnEvent) GetAuthorizerID() string

func (*WZCNBurnEvent) SetAuthorizerID

func (r *WZCNBurnEvent) SetAuthorizerID(id string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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