childchain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthCurrency     = "0x0000000000000000000000000000000000000000"
	DefaultMetadata = "0x0000000000000000000000000000000000000000000000000000000000000000"
	MaxOutputs      = 4
)

Variables

This section is empty.

Functions

func BuildTransaction

func BuildTransaction(b Builder) error

BuildTransaction to prepare for signing

func SignTransaction

func SignTransaction(s Signer, sf SignerFunc) ([][]byte, error)

SignTransaction with Signer interface and a signing function SignFunc agnostic to the actual implementation of signer function

Types

type Block

type Block struct {
	Timestamp int    `json:"timestamp"`
	Hash      string `json:"hash"`
	EthHeight int    `json:"eth_height"`
	Blknum    int    `json:"blknum"`
}

type Builder

type Builder interface {
	BuildTransaction() error
}

Builder is a struct that can build plasma tx

type ChallengeUTXOData

type ChallengeUTXOData struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    struct {
		ExitId     *big.Int `json:"exit_id"`
		InputIndex uint8    `json:"input_index"`
		Sig        string   `json:"sig"`
		Txbytes    string   `json:"txbytes"`
	} `json:"data"`
}

ChallengeUTXOData is a response from watcher from /utxo.get_challenge_data endpoint

type Client

type Client struct {
	Watcher    *url.URL
	HttpClient HttpClient
}

Client is a childchain client that holds a Watcher endpoint and HttpClient

func NewClient

func NewClient(watcher string, httpclient HttpClient) (*Client, error)

NewClient Creates new instance of child chain client with a watcher endpoint and a HTTP client

func (*Client) GetBalance

func (c *Client) GetBalance(address string) (*WatcherBalanceFromAddress, error)

GetBalance fetchs a balance for a certain address

func (*Client) GetChallengeData

func (c *Client) GetChallengeData(utxoPosition int) (*ChallengeUTXOData, error)

GetChallengeData from the watcher based on UTXO position to be used in rootchain Challenge function call

func (*Client) GetTransaction

func (c *Client) GetTransaction(txHash string) (*TransactionGetResponse, error)

GetTransaction fetches data about a certain transaction hash via transaction.get endpoint

func (*Client) GetUTXOExitData

func (c *Client) GetUTXOExitData(utxoPosition int) (*StandardExitUTXOData, error)

GetUTXOExitData from watcher based on utxo position from /utxo.get_exit_data endpoint to be used in rootchain exit function call

func (*Client) GetUTXOsFromAddress

func (c *Client) GetUTXOsFromAddress(address string) (*WatcherUTXOsFromAddress, error)

GetUTXOsFromAddress Retrieve the UTXOs associated with an address from the Watcher client

func (*Client) GetWatcher

func (c *Client) GetWatcher() string

GetWatcher returns the watcher URL string

func (*Client) GetWatcherStatus

func (c *Client) GetWatcherStatus() (*WatcherStatus, error)

GetWatcherStatus retrieves watcher status via status.get API

func (*Client) NewPaymentTx

func (c *Client) NewPaymentTx(popts ...PaymentOption) (p *PaymentTx)

type ClientError

type ClientError struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    struct {
		Object      string `json:"object"`
		Description string `json:"description"`
		Code        string `json:"code"`
	} `json:"data"`
}

ClientError is a general error message expected from a Watcher response

type ContractAddr

type ContractAddr struct {
	Erc20Vault      string `json:"erc20_vault"`
	EthVault        string `json:"eth_vault"`
	PaymentExitGame string `json:"payment_exit_game"`
	PlasmaFramework string `json:"plasma_framework"`
}

WatcherStatus is a returned response from calling status.get

type CreateTransaction

type CreateTransaction struct {
	Owner    common.Address `json:"owner"`
	Payments []Payment      `json:"payments"`
	Fee      Fee            `json:"fee"`
	Metadata string         `json:"metadata"`
}

CreateTransaction is a payload to be submitted via transaction.create endpoint

type CreateTransactionResponse

type CreateTransactionResponse struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    Data   `json:"data"`
}

type Data

type Data struct {
	Result       string         `json:"result"`
	Transactions []Transactions `json:"transactions"`
	Object       string         `json:"object"`
	Code         string         `json:"code"`
	Description  string         `json:"description"`
}

type Domain

type Domain struct {
	Name              string `json:"name"`
	Salt              string `json:"salt"`
	VerifyingContract string `json:"verifyingContract"`
	Version           string `json:"version"`
}

type EIP712Domain

type EIP712Domain struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type Fee

type Fee struct {
	// Amount   *big.Int         `json:"amount"`
	Currency common.Address `json:"currency"`
}

Fee is a amount and currency of transaction fee

type GetTxData

type GetTxData struct {
	Txindex  int       `json:"txindex"`
	Txhash   string    `json:"txhash"`
	Metadata string    `json:"metadata"`
	Txbytes  string    `json:"txbytes"`
	Block    Block     `json:"block"`
	Inputs   []Inputs  `json:"inputs"`
	Outputs  []Outputs `json:"outputs"`
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Input

type Input struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type Input0

type Input0 struct {
	Blknum  int `json:"blknum"`
	Txindex int `json:"txindex"`
	Oindex  int `json:"oindex"`
}

type Input1

type Input1 struct {
	Blknum  int `json:"blknum"`
	Txindex int `json:"txindex"`
	Oindex  int `json:"oindex"`
}

type Input2

type Input2 struct {
	Blknum  int `json:"blknum"`
	Txindex int `json:"txindex"`
	Oindex  int `json:"oindex"`
}

type Input3

type Input3 struct {
	Blknum  int `json:"blknum"`
	Txindex int `json:"txindex"`
	Oindex  int `json:"oindex"`
}

type Inputs

type Inputs struct {
	Blknum   int         `json:"blknum"`
	Txindex  int         `json:"txindex"`
	Oindex   int         `json:"oindex"`
	UtxoPos  *big.Int    `json:"utxo_pos"`
	Owner    string      `json:"owner"`
	Currency string      `json:"currency"`
	Amount   json.Number `json:"amount"`
}

type Message

type Message struct {
	Input0   Input0  `json:"input0"`
	Input1   Input1  `json:"input1"`
	Input2   Input2  `json:"input2"`
	Input3   Input3  `json:"input3"`
	Output0  Output0 `json:"output0"`
	Output1  Output1 `json:"output1"`
	Output2  Output2 `json:"output2"`
	Output3  Output3 `json:"output3"`
	Metadata string  `json:"metadata"`
}

type Output

type Output struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type Output0

type Output0 struct {
	Owner    string      `json:"owner"`
	Currency string      `json:"currency"`
	Amount   json.Number `json:"amount"`
}

type Output1

type Output1 struct {
	Owner    string      `json:"owner"`
	Currency string      `json:"currency"`
	Amount   json.Number `json:"amount"`
}

type Output2

type Output2 struct {
	Owner    string      `json:"owner"`
	Currency string      `json:"currency"`
	Amount   json.Number `json:"amount"`
}

type Output3

type Output3 struct {
	Owner    string      `json:"owner"`
	Currency string      `json:"currency"`
	Amount   json.Number `json:"amount"`
}

type Outputs

type Outputs struct {
	Amount   json.Number `json:"amount"`
	Currency string      `json:"currency"`
	Owner    string      `json:"owner"`
}

type Payment

type Payment struct {
	Amount   *big.Int       `json:"amount"`
	Currency common.Address `json:"currency"`
	Owner    common.Address `json:"owner"`
}

Payment specifies the amount, currency and recipient of the output

type PaymentOption

type PaymentOption func(*CreateTransaction)

func AddFee

func AddFee(curr common.Address) PaymentOption

func AddMetadata

func AddMetadata(m string) PaymentOption

func AddOwner

func AddOwner(o common.Address) PaymentOption

func AddPayment

func AddPayment(amount string, addr, curr common.Address) PaymentOption

type PaymentTx

type PaymentTx struct {
	Client                    *Client
	CreateTransaction         *CreateTransaction
	CreateTransactionResponse *CreateTransactionResponse
	Signatures                [][]byte
	TypedTransaction          TypedTransaction
}

PaymentTx is a general P2P payment transaction implemented using Watcher's set of convenience API it can be used to transfer funds from one to many

func (*PaymentTx) BuildTransaction

func (p *PaymentTx) BuildTransaction() error

BuildTransaction forms a transaction to be signed via transaction.create endpoint NOTE: if response.Data.Result == "intermediate" means payment cannot be completed in one transaction, this tx will automatically performs a merge instead TODO: clients should be able to respond to intermediate transactions

func (*PaymentTx) SignTransaction

func (p *PaymentTx) SignTransaction(signer SignerFunc) ([][]byte, error)

SignTransaction takes in any Signer function and uses it on the SignHash a custom signing function can be used as input

func (*PaymentTx) SubmitTransaction

func (p *PaymentTx) SubmitTransaction() (*TransactionSubmitResponse, error)

SubmitTransaction submit payment transaction through /transaction.submit_typed endpoint

type PlasmaTransaction

type PlasmaTransaction interface {
	Builder
	Signer
	Submitter
}

PlasmaTransaction interface, can build, sign, submit

type Signer

type Signer interface {
	SignTransaction(SignerFunc) ([][]byte, error)
}

Signer is a struct that can sign plasma tx

type SignerFunc

type SignerFunc func([]byte) ([][]byte, error)

SignerFunc is any function that takes in raw byte and return signature of type [][]byte

func SignWithRawKeys

func SignWithRawKeys(keys ...string) SignerFunc

SignWithRawKeys takes private key as raw strings and return a function of type SignerFunc NOTE: this is a default convenience function for signing, user should implement different Signing function

type StandardExitUTXOData

type StandardExitUTXOData struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    struct {
		UtxoPos *big.Int `json:"utxo_pos"`
		Txbytes string   `json:"txbytes"`
		Sigs    string   `json:"sigs"`
		Proof   string   `json:"proof"`
	} `json:"data"`
}

StandardExitUTXOData is a response from watcher from /utxo.get_exit_data endpoint

type Submitter

type Submitter interface {
	SubmitTransaction() (*TransactionSubmitResponse, error)
}

Submitter is a struct that can submit plasma tx

type Transaction

type Transaction struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type TransactionGetResponse

type TransactionGetResponse struct {
	Version string    `json:"version"`
	Success bool      `json:"success"`
	Data    GetTxData `json:"data"`
}

type TransactionSubmitResponse

type TransactionSubmitResponse struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    struct {
		Blknum      int    `json:"blknum"`
		Txindex     int    `json:"txindex"`
		Txhash      string `json:"txhash"`
		Object      string `json:"object"`
		Code        string `json:"code"`
		Description string `json:"description"`
		Messages    struct {
			ErrorKey string `json:"error_key"`
		} `json:"messages"`
	} `json:"data"`
}

TransactionSubmitResponse is an expected response from making transaction to watcher

func SubmitTransaction

func SubmitTransaction(s Submitter) (*TransactionSubmitResponse, error)

SubmitTransaction with submitter interface

type Transactions

type Transactions struct {
	Inputs    []Inputs  `json:"inputs"`
	Outputs   []Outputs `json:"outputs"`
	Fee       Fee       `json:"fee"`
	Metadata  string    `json:"metadata"`
	Txbytes   string    `json:"txbytes"`
	SignHash  string    `json:"sign_hash"`
	TypedData TypedData `json:"typed_data"`
}

type TypedData

type TypedData struct {
	Types       Types   `json:"types"`
	PrimaryType string  `json:"primaryType"`
	Domain      Domain  `json:"domain"`
	Message     Message `json:"message"`
}

type TypedTransaction

type TypedTransaction struct {
	Domain     Domain   `json:"domain"`
	Message    Message  `json:"message"`
	Signatures []string `json:"signatures"`
}

TypedTransaction is a transaction data to be submitted to submit_typed endpoint

type Types

type Types struct {
	EIP712Domain []EIP712Domain `json:"EIP712Domain"`
	Transaction  []Transaction  `json:"Transaction"`
	Input        []Input        `json:"Input"`
	Output       []Output       `json:"Output"`
}

type WatcherBalanceFromAddress

type WatcherBalanceFromAddress struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    []struct {
		Currency string  `json:"currency"`
		Amount   float64 `json:"amount"`
	} `json:"data"`
}

WatcherBalanceFromAddress is a returned response from calling account.get_balance

type WatcherStatus

type WatcherStatus struct {
	Data struct {
		ByzantineEvents []struct {
			Event   string                 `json:"event"`
			Details map[string]interface{} `json:"details"`
		} `json:"byzantine_events"`
		ContractAddr  ContractAddr `json:"contract_addr"`
		EthSyncing    bool         `json:"eth_syncing"`
		InFlightExits []struct {
			EthHeight          int           `json:"eth_height"`
			PiggybackedInputs  []interface{} `json:"piggybacked_inputs"`
			PiggybackedOutputs []interface{} `json:"piggybacked_outputs"`
			Txbytes            string        `json:"txbytes"`
			Txhash             string        `json:"txhash"`
		} `json:"in_flight_exits"`
		LastMinedChildBlockNumber        int `json:"last_mined_child_block_number"`
		LastMinedChildBlockTimestamp     int `json:"last_mined_child_block_timestamp"`
		LastSeenEthBlockNumber           int `json:"last_seen_eth_block_number"`
		LastSeenEthBlockTimestamp        int `json:"last_seen_eth_block_timestamp"`
		LastValidatedChildBlockNumber    int `json:"last_validated_child_block_number"`
		LastValidatedChildBlockTimestamp int `json:"last_validated_child_block_timestamp"`
		ServicesSyncedHeights            []struct {
			Height  int    `json:"height"`
			Service string `json:"service"`
		} `json:"services_synced_heights"`
	} `json:"data"`
	Success bool   `json:"success"`
	Version string `json:"version"`
}

type WatcherUTXOsFromAddress

type WatcherUTXOsFromAddress struct {
	Version string `json:"version"`
	Success bool   `json:"success"`
	Data    []struct {
		UtxoPos  *big.Int `json:"utxo_pos"`
		Txindex  int      `json:"txindex"`
		Owner    string   `json:"owner"`
		Oindex   int      `json:"oindex"`
		Currency string   `json:"currency"`
		Blknum   int      `json:"blknum"`
		Amount   float64  `json:"amount"`
	} `json:"data"`
}

WatcherUTXOsFromAddress is a returned response from calling account.get_utxos

Jump to

Keyboard shortcuts

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