nchain

package
v0.0.0-...-09899ef Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBridge

func CreateBridge(token string, params map[string]interface{}) (int, interface{}, error)

CreateBridge

func DeleteConnector

func DeleteConnector(token, connectorID string) error

DeleteConnector

func GetAccountBalance

func GetAccountBalance(token, accountID, tokenID string, params map[string]interface{}) (int, interface{}, error)

GetAccountBalance

func GetBridgeDetails

func GetBridgeDetails(token, bridgeID string, params map[string]interface{}) (int, interface{}, error)

GetBridgeDetails

func ListBridges

func ListBridges(token string, params map[string]interface{}) (int, interface{}, error)

ListBridges

func ListNetworkBlocks

func ListNetworkBlocks(token, networkID string, params map[string]interface{}) (int, interface{}, error)

ListNetworkBlocks

func ListNetworkBridges

func ListNetworkBridges(token, networkID string, params map[string]interface{}) (int, interface{}, error)

ListNetworkBridges

func UpdateNetwork

func UpdateNetwork(token, networkID string, params map[string]interface{}) error

UpdateNetwork updates an existing network

Types

type Account

type Account struct {
	api.Model

	NetworkID      *uuid.UUID `json:"network_id,omitempty"`
	WalletID       *uuid.UUID `json:"wallet_id,omitempty"`
	ApplicationID  *uuid.UUID `json:"application_id,omitempty"`
	UserID         *uuid.UUID `json:"user_id,omitempty"`
	OrganizationID *uuid.UUID `json:"organization_id,omitempty"`

	VaultID *uuid.UUID `json:"vault_id,omitempty"`
	KeyID   *uuid.UUID `json:"key_id,omitempty"`

	Type *string `json:"type,omitempty"`

	HDDerivationPath *string `json:"hd_derivation_path,omitempty"` // i.e. m/44'/60'/0'/0
	PublicKey        *string `json:"public_key,omitempty"`
	PrivateKey       *string `json:"private_key,omitempty"`

	Address    string     `json:"address"`
	Balance    *big.Int   `json:"balance,omitempty"`
	AccessedAt *time.Time `json:"accessed_at,omitempty"`
}

Account contains the specific account user details

func CreateAccount

func CreateAccount(token string, params map[string]interface{}) (*Account, error)

CreateAccount creates a new account

func GetAccountDetails

func GetAccountDetails(token, accountID string, params map[string]interface{}) (*Account, error)

GetAccountDetails

func ListAccounts

func ListAccounts(token string, params map[string]interface{}) ([]*Account, error)

ListAccounts

func ListNetworkAccounts

func ListNetworkAccounts(token, networkID string, params map[string]interface{}) ([]*Account, error)

ListNetworkAccounts

func ListWalletAccounts

func ListWalletAccounts(token, walletID string, params map[string]interface{}) ([]*Account, error)

ListWalletAccounts

type CompiledArtifact

type CompiledArtifact struct {
	Name        string          `json:"name"`
	ABI         []interface{}   `json:"abi"`
	Assembly    interface{}     `json:"assembly,omitempty"`
	Bytecode    string          `json:"bytecode"`
	Deps        []interface{}   `json:"deps,omitempty"`
	Opcodes     string          `json:"opcodes,omitempty"`
	Raw         json.RawMessage `json:"raw"`
	Source      *string         `json:"source"`
	Fingerprint *string         `json:"fingerprint"`
}

CompiledArtifact represents compiled sourcecode

type Connector

type Connector struct {
	api.Model

	ApplicationID  *uuid.UUID       `json:"application_id"`
	NetworkID      uuid.UUID        `json:"network_id"`
	OrganizationID *uuid.UUID       `json:"organization_id"`
	Name           *string          `json:"name"`
	Type           *string          `json:"type"`
	Status         *string          `json:"status"`
	Description    *string          `json:"description"`
	Config         *json.RawMessage `json:"config,omitempty"`
	IsVirtual      bool             `json:"is_virtual,omitempty"`
	AccessedAt     *time.Time       `json:"accessed_at,omitempty"`

	Details *ConnectorDetails `json:"details,omitempty"`
}

Connector instances represent a logical connection to IPFS or other decentralized filesystem; in the future it may represent a logical connection to services of other types

func CreateConnector

func CreateConnector(token string, params map[string]interface{}) (*Connector, error)

CreateConnector

func GetConnectorDetails

func GetConnectorDetails(token, connectorID string, params map[string]interface{}) (*Connector, error)

GetConnectorDetails

func ListConnectors

func ListConnectors(token string, params map[string]interface{}) ([]*Connector, error)

ListConnectors

func ListNetworkConnectors

func ListNetworkConnectors(token, networkID string, params map[string]interface{}) ([]*Connector, error)

ListNetworkConnectors

type ConnectorDetails

type ConnectorDetails struct {
	Page *int64      `json:"page,omitempty"`
	RPP  *int64      `json:"rpp,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

ConnectorDetails is a generic representation for a type-specific enrichment of a described connector; the details object may have complexity of its own, such as paginated subresults

type Contract

type Contract struct {
	api.Model

	ApplicationID *uuid.UUID `json:"application_id"`
	NetworkID     uuid.UUID  `json:"network_id"`
	ContractID    *uuid.UUID `json:"contract_id"`    // id of the contract which created the contract (or null)
	TransactionID *uuid.UUID `json:"transaction_id"` // id of the transaction which deployed the contract (or null)

	Name         *string          `json:"name"`
	Address      *string          `json:"address"`
	Type         *string          `json:"type"`
	Params       *json.RawMessage `json:"params,omitempty"`
	AccessedAt   *time.Time       `json:"accessed_at"`
	PubsubPrefix *string          `json:"pubsub_prefix,omitempty"`
}

Contract instances must be associated with an application identifier.

func CreateContract

func CreateContract(token string, params map[string]interface{}) (*Contract, error)

CreateContract

func CreatePublicContract

func CreatePublicContract(token string, params map[string]interface{}) (*Contract, error)

CreatePublicContract loads an already deployed contract into nchain for arbitrary transaction execution this can be used for org registries, erc20 etc.

func GetContractDetails

func GetContractDetails(token, contractID string, params map[string]interface{}) (*Contract, error)

GetContractDetails

func GetNetworkContractDetails

func GetNetworkContractDetails(token, networkID, contractID string, params map[string]interface{}) (*Contract, error)

GetNetworkContractDetails

func ListContracts

func ListContracts(token string, params map[string]interface{}) ([]*Contract, error)

ListContracts

func ListNetworkContracts

func ListNetworkContracts(token, networkID string, params map[string]interface{}) ([]*Contract, error)

ListNetworkContracts

type ContractExecutionResponse

type ContractExecutionResponse struct {
	Confidence float64     `json:"confidence"`
	Reference  *string     `json:"ref"`
	Response   interface{} `json:"response,omitempty"`
}

ContractExecutionResponse is a response from the contract execution call

func ExecuteContract

func ExecuteContract(token, contractID string, params map[string]interface{}) (*ContractExecutionResponse, error)

ExecuteContract

type EthereumJsonRpcResponse

type EthereumJsonRpcResponse struct {
	ID     interface{}                   `json:"id"`
	Result interface{}                   `json:"result"`
	Error  *EthereumJsonRpcResponseError `json:"error,omitempty"`
}

EthereumJsonRpcResponse is a generic handler for ethereum JSON-RPC responses

type EthereumJsonRpcResponseError

type EthereumJsonRpcResponseError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

EthereumJsonRpcResponseError is a generic error representation for ethereum JSON-RPC responses

type EthereumTxTraceResponse

type EthereumTxTraceResponse struct {
	Result []struct {
		Action struct {
			CallType *string `json:"callType"`
			From     *string `json:"from"`
			Gas      *string `json:"gas"`
			Init     *string `json:"init"`
			Input    *string `json:"input"`
			To       *string `json:"to"`
			Value    *string `json:"value"`
		} `json:"action"`
		BlockHash   *string `json:"blockHash"`
		BlockNumber int     `json:"blockNumber"`
		Result      struct {
			Address *string `json:"address"`
			Code    *string `json:"code"`
			GasUsed *string `json:"gasUsed"`
			Output  *string `json:"output"`
		} `json:"result"`
		Error               *string       `json:"error"`
		Subtraces           int           `json:"subtraces"`
		TraceAddress        []interface{} `json:"traceAddress"`
		TransactionHash     *string       `json:"transactionHash"`
		TransactionPosition int           `json:"transactionPosition"`
		Type                *string       `json:"type"`
	} `json:"result"`
}

EthereumTxTraceResponse is returned upon successful contract execution

type EthereumWebsocketSubscriptionResponse

type EthereumWebsocketSubscriptionResponse struct {
	ID     interface{}            `json:"id"`
	Params map[string]interface{} `json:"params"`
}

EthereumWebsocketSubscriptionResponse is a generic handler for ethereum websocket subscription responses

type Network

type Network struct {
	api.Model

	ApplicationID *uuid.UUID       `json:"application_id,omitempty"`
	UserID        *uuid.UUID       `json:"user_id,omitempty"`
	Name          *string          `json:"name"`
	Description   *string          `json:"description"`
	Enabled       *bool            `json:"enabled"`
	ChainID       *string          `json:"chain_id"`             // protocol-specific chain id
	NetworkID     *uuid.UUID       `json:"network_id,omitempty"` // network id used as the parent
	Config        *json.RawMessage `json:"config,omitempty"`
}

Network contains the specific Ethereum network details (mainnet, etc.)

func CreateNetwork

func CreateNetwork(token string, params map[string]interface{}) (*Network, error)

CreateNetwork creates a new network

func GetNetworkDetails

func GetNetworkDetails(token, networkID string, params map[string]interface{}) (*Network, error)

GetNetworkDetails returns the details for the specified network id

func ListNetworks

func ListNetworks(token string, params map[string]interface{}) ([]*Network, error)

ListNetworks

type NetworkStatus

type NetworkStatus struct {
	Block           uint64                 `json:"block,omitempty"`            // current block
	ChainID         *string                `json:"chain_id,omitempty"`         // the chain id
	Height          *uint64                `json:"height,omitempty"`           // total height of the blockchain; null after syncing completed
	LastBlockAt     *uint64                `json:"last_block_at,omitempty"`    // unix timestamp of the last block; i.e., when the last block was collated
	PeerCount       uint64                 `json:"peer_count,omitempty"`       // number of peers connected to the JSON-RPC client
	ProtocolVersion *string                `json:"protocol_version,omitempty"` // protocol version
	State           *string                `json:"state,omitempty"`            // i.e., syncing, synced, etc
	Syncing         bool                   `json:"syncing,omitempty"`          // when true, the network is in the process of syncing the ledger; available functionaltiy will be network-specific
	Meta            map[string]interface{} `json:"meta,omitempty"`             // network-specific metadata
}

NetworkStatus provides network-agnostic status

func GetNetworkStatusMeta

func GetNetworkStatusMeta(token, networkID string, params map[string]interface{}) (*NetworkStatus, error)

GetNetworkStatusMeta returns the status details for the specified network

type Oracle

type Oracle struct {
	api.Model

	ApplicationID *uuid.UUID `json:"application_id"`
	NetworkID     uuid.UUID  `json:"network_id"`
	ContractID    uuid.UUID  `json:"contract_id"`

	Name          *string          `json:"name"`
	FeedURL       *url.URL         `json:"feed_url"`
	Params        *json.RawMessage `json:"params"`
	AttachmentIds []*uuid.UUID     `json:"attachment_ids"`
}

Oracle instances are smart contracts whose terms are fulfilled writing data from a configured feed onto the blockchain

func CreateOracle

func CreateOracle(token string, params map[string]interface{}) (*Oracle, error)

CreateOracle

func GetOracleDetails

func GetOracleDetails(token, oracleID string, params map[string]interface{}) (*Oracle, error)

GetOracleDetails

func ListNetworkOracles

func ListNetworkOracles(token, networkID string, params map[string]interface{}) ([]*Oracle, error)

ListNetworkOracles

func ListOracles

func ListOracles(token string, params map[string]interface{}) ([]*Oracle, error)

ListOracles

type Service

type Service struct {
	api.Client
}

Service for the nchain api

func InitNChainService

func InitNChainService(token string) *Service

InitNChainService convenience method to initialize an `nchain.Service` instance

type Token

type Token struct {
	api.Model

	ApplicationID  *uuid.UUID `json:"application_id"`
	NetworkID      uuid.UUID  `json:"network_id"`
	ContractID     *uuid.UUID `json:"contract_id"`
	SaleContractID *uuid.UUID `json:"sale_contract_id"`

	Name        *string    `json:"name"`
	Symbol      *string    `json:"symbol"`
	Decimals    uint64     `json:"decimals"`
	Address     *string    `json:"address"`      // network-specific token contract address
	SaleAddress *string    `json:"sale_address"` // non-null if token sale contract is specified
	AccessedAt  *time.Time `json:"accessed_at"`
}

Token contract

func CreateTokenContract

func CreateTokenContract(token string, params map[string]interface{}) (*Token, error)

CreateTokenContract

func GetTokenContractDetails

func GetTokenContractDetails(token, tokenID string, params map[string]interface{}) (*Token, error)

GetTokenContractDetails

func ListNetworkTokens

func ListNetworkTokens(token, networkID string, params map[string]interface{}) ([]*Token, error)

ListNetworkTokens

func ListTokenContracts

func ListTokenContracts(token string, params map[string]interface{}) ([]*Token, error)

ListTokenContracts

type Transaction

type Transaction struct {
	api.Model
	NetworkID uuid.UUID `json:"network_id,omitempty"`

	// Application or user id, if populated, is the entity for which the transaction was custodially signed and broadcast
	ApplicationID *uuid.UUID `json:"application_id,omitempty"`
	UserID        *uuid.UUID `json:"user_id,omitempty"`

	// Account or HD wallet which custodially signed the transaction; when an HD wallet is used, if no HD derivation path is provided,
	// the most recently derived non-zero account is used to sign
	AccountID *uuid.UUID `json:"account_id,omitempty"`
	WalletID  *uuid.UUID `json:"wallet_id,omitempty"`
	Path      *string    `json:"hd_derivation_path,omitempty"`

	// Network-agnostic tx fields
	Signer      *string          `json:"signer,omitempty"`
	To          *string          `json:"to"`
	Value       *TxValue         `json:"value"`
	Data        *string          `json:"data"`
	Hash        *string          `json:"hash"`
	Status      *string          `json:"status"`
	Params      *json.RawMessage `json:"params,omitempty"`
	Ref         *string          `json:"ref"`
	Description *string          `json:"description"`

	// Ephemeral fields for managing the tx/rx and tracing lifecycles
	Traces interface{} `json:"traces,omitempty"`

	// Transaction metadata/instrumentation
	Block          *uint64    `json:"block"`
	BlockTimestamp *time.Time `json:"block_timestamp,omitempty"` // timestamp when the tx was finalized on-chain, according to its tx receipt
	BroadcastAt    *time.Time `json:"broadcast_at,omitempty"`    // timestamp when the tx was broadcast to the network
	FinalizedAt    *time.Time `json:"finalized_at,omitempty"`    // timestamp when the tx was finalized on-platform
	PublishedAt    *time.Time `json:"published_at,omitempty"`    // timestamp when the tx was published to NATS cluster
	QueueLatency   *uint64    `json:"queue_latency,omitempty"`   // broadcast_at - published_at (in millis) -- the amount of time between when a message is enqueued to the NATS broker and when it is broadcast to the network
	NetworkLatency *uint64    `json:"network_latency,omitempty"` // finalized_at - broadcast_at (in millis) -- the amount of time between when a message is broadcast to the network and when it is finalized on-chain
	E2ELatency     *uint64    `json:"e2e_latency,omitempty"`     // finalized_at - published_at (in millis) -- the amount of time between when a message is published to the NATS broker and when it is finalized on-chain
}

Transaction instances are associated with a signing wallet and exactly one matching instance of either an a) application identifier or b) user identifier.

func CreateTransaction

func CreateTransaction(token string, params map[string]interface{}) (*Transaction, error)

CreateTransaction

func GetNetworkTransactionDetails

func GetNetworkTransactionDetails(token, networkID, txID string, params map[string]interface{}) (*Transaction, error)

GetNetworkTransactionDetails

func GetTransactionDetails

func GetTransactionDetails(token, txID string, params map[string]interface{}) (*Transaction, error)

GetTransactionDetails

func ListNetworkTransactions

func ListNetworkTransactions(token, networkID string, params map[string]interface{}) ([]*Transaction, error)

ListNetworkTransactions

func ListTransactions

func ListTransactions(token string, params map[string]interface{}) ([]*Transaction, error)

ListTransactions

type TxReceipt

type TxReceipt struct {
	TxHash            common.Hash    `json:"hash"`
	ContractAddress   common.Address `json:"contract_address"`
	GasUsed           uint64         `json:"gas_used"`
	BlockHash         common.Hash    `json:"block_hash,omitempty"`
	BlockNumber       *big.Int       `json:"block,omitempty"`
	TransactionIndex  uint           `json:"transaction_index"`
	PostState         []byte         `json:"root"`
	Status            uint64         `json:"status"`
	CumulativeGasUsed uint64         `json:"cumulative_gas_used"`
	Bloom             interface{}    `json:"logs_bloom"`
	Logs              []interface{}  `json:"logs"`
}

TxReceipt is generalized transaction receipt model

type TxTrace

type TxTrace struct {
	Result []struct {
		Action struct {
			CallType *string `json:"callType"`
			From     *string `json:"from"`
			Gas      *string `json:"gas"`
			Init     *string `json:"init"`
			Input    *string `json:"input"`
			To       *string `json:"to"`
			Value    *string `json:"value"`
		} `json:"action"`
		BlockHash   *string `json:"blockHash"`
		BlockNumber int     `json:"blockNumber"`
		Result      struct {
			Address *string `json:"address"`
			Code    *string `json:"code"`
			GasUsed *string `json:"gasUsed"`
			Output  *string `json:"output"`
		} `json:"result"`
		Error               *string       `json:"error"`
		Subtraces           int           `json:"subtraces"`
		TraceAddress        []interface{} `json:"traceAddress"`
		TransactionHash     *string       `json:"transactionHash"`
		TransactionPosition int           `json:"transactionPosition"`
		Type                *string       `json:"type"`
	} `json:"result"`
}

TxTrace is generalized transaction trace model

type TxValue

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

TxValue provides JSON marshaling and gorm driver support for wrapping/unwrapping big.Int

func NewTxValue

func NewTxValue(val int64) *TxValue

NewTxValue is a convenience method to return a TxValue

func (*TxValue) BigInt

func (v *TxValue) BigInt() *big.Int

BigInt returns the value represented as big.Int

func (*TxValue) MarshalJSON

func (v *TxValue) MarshalJSON() ([]byte, error)

MarshalJSON marshals the tx value to bytes

func (*TxValue) Scan

func (v *TxValue) Scan(val interface{}) error

Scan reads the persisted value using the gorm driver and marshals it into a TxValue

func (*TxValue) UnmarshalJSON

func (v *TxValue) UnmarshalJSON(data []byte) error

UnmarshalJSON sets the tx value big.Int from its string representation

func (*TxValue) Value

func (v *TxValue) Value() (driver.Value, error)

Value returns the underlying big.Int as a string for use by the gorm driver (psql)

type Wallet

type Wallet struct {
	api.Model

	WalletID       *uuid.UUID `json:"wallet_id,omitempty"`
	ApplicationID  *uuid.UUID `json:"application_id,omitempty"`
	UserID         *uuid.UUID `json:"user_id,omitempty"`
	OrganizationID *uuid.UUID `json:"organization_id,omitempty"`

	VaultID *uuid.UUID `json:"vault_id,omitempty"`
	KeyID   *uuid.UUID `json:"key_id,omitempty"`

	Path     *string `json:"path,omitempty"`
	Purpose  *int    `json:"purpose,omitempty"`
	Mnemonic *string `json:"mnemonic,omitempty"`

	PublicKey  *string `json:"public_key,omitempty"`
	PrivateKey *string `json:"private_key,omitempty"`
}

Wallet contains the specific wallet details

func CreateWallet

func CreateWallet(token string, params map[string]interface{}) (*Wallet, error)

CreateWallet

func GetWalletDetails

func GetWalletDetails(token, walletID string, params map[string]interface{}) (*Wallet, error)

GetWalletDetails

func ListWallets

func ListWallets(token string, params map[string]interface{}) ([]*Wallet, error)

ListWallets

Jump to

Keyboard shortcuts

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