Documentation ¶
Overview ¶
Package dragonchain is used to interact programmatically with dragonchains.
Index ¶
- Constants
- Variables
- type AuthKey
- type Authenticator
- type BitcoinOutputs
- type BitcoinTransaction
- type Block
- type BlockHeader
- type BlockProof
- type Client
- func (client *Client) CreateAPIKey() (*Response, error)
- func (client *Client) CreateBitcoinTransaction(btcTransaction *BitcoinTransaction) (*Response, error)
- func (client *Client) CreateBulkTransaction(txn []*CreateTransaction) (_ *Response, err error)
- func (client *Client) CreateEthereumTransaction(ethTransaction *EthereumTransaction) (*Response, error)
- func (client *Client) CreateFactor(factor string) (_ *Response, err error)
- func (client *Client) CreateSmartContract(contract *ContractConfiguration) (_ *Response, err error)
- func (client *Client) CreateTransaction(txn *CreateTransaction) (_ *Response, err error)
- func (client *Client) CreateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (_ *Response, err error)
- func (client *Client) DeleteAPIKey(apiKey string) (*Response, error)
- func (client *Client) DeleteContract(smartContractID string) (*Response, error)
- func (client *Client) DeleteFactor(id string) (*Response, error)
- func (client *Client) DeleteTransactionType(transactionType string) (*Response, error)
- func (client *Client) GetAPIKey(keyID string) (*Response, error)
- func (client *Client) GetBlock(blockID string) (*Response, error)
- func (client *Client) GetPublicBlockchainAddress() (*Response, error)
- func (client *Client) GetSmartContract(smartContractID, transactionType string) (*Response, error)
- func (client *Client) GetSmartContractObject(key, smartContractID string) (*Response, error)
- func (client *Client) GetSmartContractSecret(secretName string) (_ string, err error)
- func (client *Client) GetStatus() (*Response, error)
- func (client *Client) GetTransaction(txnID string) (*Response, error)
- func (client *Client) GetTransactionType(transactionType string) (*Response, error)
- func (client *Client) GetVerifications(blockID string, level int) (*Response, error)
- func (client *Client) ListAPIKeys() (*Response, error)
- func (client *Client) ListFactors() (*Response, error)
- func (client *Client) ListSmartContractObjects(folder, smartContractID string) (*Response, error)
- func (client *Client) ListTransactionTypes() (*Response, error)
- func (client *Client) QueryBlocks(query *Query) (*Response, error)
- func (client *Client) QuerySmartContracts(query *Query) (*Response, error)
- func (client *Client) QueryTransactions(query *Query) (*Response, error)
- func (client *Client) UpdateSmartContract(contract *ContractConfiguration) (*Response, error)
- func (client *Client) UpdateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (*Response, error)
- type Configuration
- type Contract
- type ContractConfiguration
- type ContractStatus
- type CreateTransaction
- type Credentials
- type CustomIndexStructure
- type ErrFailedRequest
- type EthereumTransaction
- type Factor
- type GetSmartContractHeap
- type Header
- type L1Verification
- type L2Verification
- type L3Verification
- type L4Verification
- type Proof
- type Query
- type Response
- type Transaction
- type TransactionType
- type Verification
Constants ¶
const ( HashSHA256 = "SHA256" HashSHA3256 = "SHA3-256" HashBLAKE2b512 = "BLAKE2b512" )
Supported hash functions
const MaxBulkPutSize = 250
MaxBulkPutSize is the configurable limit of how many txn can be included in a bulk operation.
Variables ¶
var ( EnvDcIDName = "DRAGONCHAIN_ID" EnvKeyName = "AUTH_KEY" EnvKeyIDName = "AUTH_KEY_ID" )
Environment variables used to get chainID and Keys. These can be overridden before calling NewCredentials.
var BitcoinNetworks = map[string]bool{ "BTC_MAINNET": true, "BTC_TESTNET3": true, }
BitcoinNetworks supported for interchain capabilities
var ConfigFilePath = ""
ConfigFilePath points to the location of the Configuration file Default on windows '%LOCALAPPDATA%\dragonchain\credentials' Default on linux '$HOME/.dragonchain/credentials' This may be overridden before creating Credentials
var ErrDCTimeout = errors.New("chain api returned 408 timeout request")
ErrDCTimeout is thrown when the chain API returns a timeout.
var ErrInvalidLimit = errors.New("invalid limit given, must be positive int")
ErrInvalidLimit is thrown when a negative limit is provided.
var ErrInvalidOffset = errors.New("invalid offset given, must be positive int")
ErrInvalidOffset is thrown when a negative offset is provided.
var ErrMaxBulkSizeExceeded = errors.New("too many transactions. transaction count can not be greater than MaxBulkPutSize")
ErrMaxBulkSizeExceeded is thrown when bulk requests exceed MaxBulkPutSize.
var ErrNoConfigurationFileFound = errors.New("no Configuration file found")
ErrNoConfigurationFileFound is returned if no config was found in ConfigFilePath.
var ErrNoCredentials = errors.New("no credentials found")
ErrNoCredentials is thrown if no credentials file can be found.
var ErrUnsupportedHashAlgo = errors.New("hash method not supported")
ErrUnsupportedHashAlgo is thrown when an unsupported hash method is provided.
var EthereumNetworks = map[string]bool{ "ETH_MAINNET": true, "ETH_ROPSTEN": true, "ETC_MAINNET": true, "ETC_MORDEN": true, }
EthereumNetworks supported for interchain capabilities
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface { GetDragonchainID() string GetAuthorization(httpVerb, path string, timestamp, contentType, content string) string }
Authenticator generates the authentication header for requests to chain.
type BitcoinOutputs ¶
type BitcoinOutputs struct { ScriptPubKey string `json:"scriptPubKey"` Value float32 `json:"value,omitempty"` }
BitcoinOutputs are optional outputs for a bitcoin transaction.
type BitcoinTransaction ¶
type BitcoinTransaction struct { Network string `json:"network"` SatoshisPerByte float32 `json:"satoshisPerByte,omitempty"` Data string `json:"data,omitempty"` ChangeAddress string `json:"changeAddress,omitempty"` Outputs []BitcoinOutputs `json:"outputs,omitempty"` }
BitcoinTransaction represents a transaction on a bitcoin chain.
type Block ¶
type Block struct { Version string `json:"version"` DCRN string `json:"dcrn"` Header BlockHeader `json:"header"` Proof BlockProof `json:"proof"` Transactions []Transaction `json:"transactions,omitempty"` // L1 only Validation L1Verification `json:"validation,omitempty"` // L2 only L2Validations L2Verification `json:"l2-validations,omitempty"` // L3 only L3Validations []L3Verification `json:"l3-validations,omitempty"` // L4 only L4Blocks []string `json:"l4-blocks,omitempty"` // L5 only }
Block defines the structure of a finalized block.
type BlockHeader ¶
type BlockHeader struct { DcID string `json:"dc_id"` DDSS string `json:"current_ddss"` Level int `json:"level"` BlockID string `json:"block_id"` Timestamp string `json:"timestamp"` PrevProof string `json:"prev_proof"` PreviousID string `json:"prev_id"` // L4 only headers L1BlockID string `json:"l1_block_id,omitempty"` L1ChainID string `json:"l1_dc_id,omitempty"` L1Proof string `json:"l1_proof,omitempty"` }
BlockHeader defines the structure of a block's header
type BlockProof ¶
type BlockProof struct { Scheme string `json:"scheme"` Proof string `json:"proof,omitempty"` Nonce int `json:"nonce,omitempty"` // Used for PoW chains. // L5 only proofs BlockLastSentAt int64 `json:"block_last_sent_at,omitempty"` TxnHash []string `json:"transaction_hash,omitempty"` Network string `json:"network,omitempty"` }
BlockProof defines the structure of a signature proof.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines the structure of the DragonchainSDK client.
func NewClient ¶
func NewClient(creds Authenticator, apiBaseURL string, httpClient httpClient) *Client
NewClient creates a new instance of client. By default, it does not generate usable credentials. Accepts Authenticator credentials created using dragonchain.NewCredentials. apiBaseUrl is optional and for use when interacting with chains outside of the managed service. httpClient is optional if you wish to designate custom headers for requests.
func (*Client) CreateAPIKey ¶
CreateAPIKey to access chain with.
func (*Client) CreateBitcoinTransaction ¶
func (client *Client) CreateBitcoinTransaction(btcTransaction *BitcoinTransaction) (*Response, error)
CreateBitcoinTransaction creates an interchain btc transaction using this chain's interchain address.
func (*Client) CreateBulkTransaction ¶
func (client *Client) CreateBulkTransaction(txn []*CreateTransaction) (_ *Response, err error)
CreateBulkTransaction sends many transactions to a chain in a single HTTP request.
func (*Client) CreateEthereumTransaction ¶
func (client *Client) CreateEthereumTransaction(ethTransaction *EthereumTransaction) (*Response, error)
CreateEthereumTransaction creates an interchain eth transaction using this chain's interchain address.
func (*Client) CreateFactor ¶
CreateFactor creates a new factor.
func (*Client) CreateSmartContract ¶
func (client *Client) CreateSmartContract(contract *ContractConfiguration) (_ *Response, err error)
CreateSmartContract creates a new smart contract on the chain.
func (*Client) CreateTransaction ¶
func (client *Client) CreateTransaction(txn *CreateTransaction) (_ *Response, err error)
CreateTransaction creates a transaction on the chain.
func (*Client) CreateTransactionType ¶
func (client *Client) CreateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (_ *Response, err error)
CreateTransactionType creates a new transaction type.
func (*Client) DeleteAPIKey ¶
DeleteAPIKey from chain.
func (*Client) DeleteContract ¶
DeleteContract removes a contract from the chain.
func (*Client) DeleteFactor ¶
DeleteFactor removes the specified factor.
func (*Client) DeleteTransactionType ¶
DeleteTransactionType removes the specified transaction type. It will not affect transactions that have already been processed.
func (*Client) GetPublicBlockchainAddress ¶
GetPublicBlockchainAddress returns a dictionary of this chain's interchain addresses. This method is only supported on L1 and L5 chains.
func (*Client) GetSmartContract ¶
GetSmartContract returns details on a smart contract by ID or transactionType. If both contractID and transactionType are provided, contractID is used.
func (*Client) GetSmartContractObject ¶
GetSmartContractObject returns a specific key from a smart contract's heap. If SCName is not provided, the SDK will try to pull it from the environment.
func (*Client) GetSmartContractSecret ¶
GetSmartContractSecret pulls a secret for the running smart contract from the chain.
func (*Client) GetTransaction ¶
GetTransaction gets a transaction from the chain by id.
func (*Client) GetTransactionType ¶
GetTransactionType returns a transaction type on chain by its name.
func (*Client) GetVerifications ¶
GetVerifications returns a block's verification at a specific level of DragonNet.
func (*Client) ListAPIKeys ¶
ListAPIKeys for a chain.
func (*Client) ListFactors ¶
ListFactors lists out all registered factors for a chain.
func (*Client) ListSmartContractObjects ¶
ListSmartContractObjects lists out all keys from a smart contract's heap. Optionally, folder can be provided to only list a subset of keys.
func (*Client) ListTransactionTypes ¶
ListTransactionTypes lists out all registered transaction types for a chain.
func (*Client) QueryBlocks ¶
QueryBlocks gets all blocks matching the given query.
func (*Client) QuerySmartContracts ¶
QuerySmartContracts returns a list of matching contracts on the chain.
func (*Client) QueryTransactions ¶
QueryTransactions gets all transactions matching the given query on the chain.
func (*Client) UpdateSmartContract ¶
func (client *Client) UpdateSmartContract(contract *ContractConfiguration) (*Response, error)
UpdateSmartContract updates an existing contract with a new configuration. Configuration details that aren't provided will not be changed.
func (*Client) UpdateTransactionType ¶
func (client *Client) UpdateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (*Response, error)
UpdateTransactionType updates a given transaction type.
type Configuration ¶
Configuration defines the SDK configuration of chainID and AuthKeys.
func GetCredentialConfigs ¶
func GetCredentialConfigs() (*Configuration, error)
GetCredentialConfigs returns
type Contract ¶
type Contract struct { TransactionType string `json:"txn_type"` ContractID string `json:"id"` Status ContractStatus `json:"status"` Image string `json:"image"` AuthKeyID string `json:"auth_key_id"` ImageDigest string `json:"image_digest"` Cmd string `json:"cmd"` Args []string `json:"args"` Env map[string]interface{} `json:"env"` ExistingSecrets []string `json:"existing_secrets"` Cron string `json:"cron"` Seconds string `json:"seconds"` ExecutionOrder string `json:"execution_order"` }
Contract defines the structure of a deployed smart contract.
type ContractConfiguration ¶
type ContractConfiguration struct { TransactionType string `json:"txn_type"` Image string `json:"image"` Cmd string `json:"cmd"` Args []string `json:"args"` ExecutionOrder string `json:"execution_order"` Enabled bool `json:"enabled"` EnvironmentVariables []string `json:"env"` Secrets map[string]interface{} `json:"secrets"` ScheduleIntervalInSeconds int `json:"seconds"` CronExpression string `json:"cron"` RegistryCredentials string `json:"auth"` }
ContractConfiguration defines the structure of a request to create a new smart contract.
type ContractStatus ¶
type ContractStatus struct { State string `json:"state"` Msg string `json:"msg"` Timestamp string `json:"timestamp"` }
ContractStatus defines the status object for contracts.
type CreateTransaction ¶
type CreateTransaction struct { Version string `json:"version"` TransactionType string `json:"txn_type"` Tag string `json:"tag"` Payload map[string]interface{} `json:"payload"` }
CreateTransaction defines the transaction schema for dragonchain.
type Credentials ¶
type Credentials struct {
// contains filtered or unexported fields
}
Credentials implements the Authenticator interface to generate authentication headers.
func NewCredentials ¶
func NewCredentials(dcID, authKey, authKeyID, algorithm string) (*Credentials, error)
NewCredentials uses the provided values to create a new Credentials instance for the given chain.
func (*Credentials) GetAuthorization ¶
func (creds *Credentials) GetAuthorization(httpVerb, path string, timestamp, contentType, content string) string
GetAuthorization returns the current chain's authorization as a string.
func (*Credentials) GetDragonchainID ¶
func (creds *Credentials) GetDragonchainID() string
GetDragonchainID returns the current chain's ID.
type CustomIndexStructure ¶
CustomIndexStructure defines the valid format of custom indexes on a transaction type.
type ErrFailedRequest ¶
ErrFailedRequest defines the structure of an error returned by the chain.
func NewRequestError ¶
func NewRequestError(resp *http.Response) *ErrFailedRequest
NewRequestError returns a formatted ErrFailedRequest object from the chain's http response.
func (ErrFailedRequest) Error ¶
func (err ErrFailedRequest) Error() string
type EthereumTransaction ¶
type EthereumTransaction struct { Network string `json:"network"` To string `json:"to"` Value string `json:"value"` Data string `json:"data,omitempty"` GasPrice string `json:"gasPrice,omitempty"` Gas string `json:"gas,omitempty"` }
EthereumTransaction represents a transaction on an ethereum chain.
type Factor ¶
type Factor struct { Version string `json:"version,omitempty"` Id string `json:"fct_id,omitempty"` Factor string `json:"factor,omitempty"` }
Factor defines the complete factor on a dragonchain.
type GetSmartContractHeap ¶
GetSmartContractHeap defines the request format for getting a key from a Smart Contract's heap.
type Header ¶
type Header struct { TransactionType string `json:"txn_type"` DcID string `json:"dc_id"` TxnID string `json:"txn_id"` BlockID string `json:"block_id"` TimeStamp string `json:"timestamp"` Tag string `json:"tag"` Invoker string `json:"invoker"` }
Header defines the HTTP headers required for dragonchain authentication
type L1Verification ¶
type L1Verification struct { BlockID string `json:"block_id"` ChainID string `json:"dc_id"` StrippedProof string `json:"stripped_proof"` Transactions string `json:"transactions"` }
L1Verification is a representation of an L1 block verified by an L2 chain.
type L2Verification ¶
type L2Verification struct { Clouds []string Count string DDSS string `json:"ddss"` L1BlockID string `json:"l1_block_id"` L1ChainID string `json:"l1_dc_id"` L1Proof string `json:"l1_proof"` Regions []string }
L2Verification is a representation of an L2 block verified by an L3 chain.
type L3Verification ¶
type L3Verification struct { L3ChainID string `json:"l3_dc_id"` L3BlockID string `json:"l3_block_id"` L3Proof string `json:"l3_proof"` Valid bool `json:"valid"` }
L3Verification is a representation of an L3 block verified by an L4 chain.
type L4Verification ¶
type L4Verification struct { L1ChainID string `json:"l1_dc_id"` L1BlockID string `json:"l1_block_id"` L4ChainID string `json:"l4_dc_id"` L4BlockID string `json:"l4_block_id"` L4Proof string `json:"l4_proof"` }
L4Verification is a representation of an L4 block verified by an L4 chain.
type Query ¶
type Query struct { Query string `json:"q"` Sort string `json:"sort"` Offset int `json:"offset"` Limit int `json:"limit"` }
Query defines the structure of a lucene query on the Dragonchain.
type Response ¶
type Response struct { OK bool `json:"ok"` Status int `json:"status"` Response interface{} `json:"response"` }
Response defines the standard response all chains will use.
type Transaction ¶
type Transaction struct { Version string `json:"version"` DCRN string `json:"dcrn"` Header Header `json:"header"` Payload map[string]interface{} `json:"payload"` Proof Proof `json:"proof"` }
Transaction defines the complete transaction on a dragonchain.
type TransactionType ¶
type TransactionType struct { Version string `json:"version"` Type string `json:"txn_type"` CustomIndexes []CustomIndexStructure `json:"custom_indexes"` IsContract bool `json:"is_contract"` }
TransactionType defines the properties of a valid Dragonchain transaction type.