dragonchain-sdk-go: github.com/dragonchain/dragonchain-sdk-go Index | Files

package dragonchain

import "github.com/dragonchain/dragonchain-sdk-go"

Package dragonchain is used to interact programmatically with dragonchains.


Package Files

block.go client.go configuration.go contract.go credentials.go errors.go query.go transaction.go verification.go


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.


var (
    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

type AuthKey Uses

type AuthKey struct {
    AuthKey   string
    AuthKeyID string

AuthKey defines the structure of the chain's HMAC authorization keys.

type Authenticator Uses

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 Uses

type BitcoinOutputs struct {
    ScriptPubKey string  `json:"scriptPubKey"`
    Value        float32 `json:"value,omitempty"`

BitcoinOutputs are optional outputs for a bitcoin transaction.

type BitcoinTransaction Uses

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 Uses

type Block struct {
    Version       string `json:"version"`
    DCRN          string `json:"dcrn"`
    Header        BlockHeader
    Proof         BlockProof
    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 Uses

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 Uses

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 string   `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 Uses

type Client struct {
    // contains filtered or unexported fields

Client defines the structure of the DragonchainSDK client.

func NewClient Uses

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 Uses

func (client *Client) CreateAPIKey() (*Response, error)

CreateAPIKey to access chain with.

func (*Client) CreateBitcoinTransaction Uses

func (client *Client) CreateBitcoinTransaction(btcTransaction *BitcoinTransaction) (*Response, error)

CreateBitcoinTransaction creates an interchain btc transaction using this chain's interchain address.

func (*Client) CreateBulkTransaction Uses

func (client *Client) CreateBulkTransaction(txn []*CreateTransaction) (_ *Response, err error)

CreateBulkTransaction sends many transactions to a chain in a single HTTP request.

func (*Client) CreateEthereumTransaction Uses

func (client *Client) CreateEthereumTransaction(ethTransaction *EthereumTransaction) (*Response, error)

CreateEthereumTransaction creates an interchain eth transaction using this chain's interchain address.

func (*Client) CreateSmartContract Uses

func (client *Client) CreateSmartContract(contract *ContractConfiguration) (_ *Response, err error)

CreateSmartContract creates a new smart contract on the chain.

func (*Client) CreateTransaction Uses

func (client *Client) CreateTransaction(txn *CreateTransaction) (_ *Response, err error)

CreateTransaction creates a transaction on the chain.

func (*Client) CreateTransactionType Uses

func (client *Client) CreateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (_ *Response, err error)

CreateTransactionType creates a new transaction type.

func (*Client) DeleteAPIKey Uses

func (client *Client) DeleteAPIKey(keyID string) (*Response, error)

DeleteAPIKey from chain.

func (*Client) DeleteContract Uses

func (client *Client) DeleteContract(smartContractID string) (*Response, error)

DeleteContract removes a contract from the chain.

func (*Client) DeleteTransactionType Uses

func (client *Client) DeleteTransactionType(transactionType string) (*Response, error)

DeleteTransactionType removes the specified transaction type. It will not affect transactions that have already been processed.

func (*Client) GetAPIKey Uses

func (client *Client) GetAPIKey(keyID string) (*Response, error)

GetAPIKey returns an HMAC API key.

func (*Client) GetBlock Uses

func (client *Client) GetBlock(blockID string) (*Response, error)

GetBlock returns a block by ID.

func (*Client) GetPublicBlockchainAddress Uses

func (client *Client) GetPublicBlockchainAddress() (*Response, error)

GetPublicBlockchainAddress returns a dictionary of this chain's interchain addresses. This method is only supported on L1 and L5 chains.

func (*Client) GetSmartContract Uses

func (client *Client) GetSmartContract(smartContractID, transactionType string) (*Response, error)

GetSmartContract returns details on a smart contract by ID or transactionType. If both contractID and transactionType are provided, contractID is used.

func (*Client) GetSmartContractObject Uses

func (client *Client) GetSmartContractObject(key, smartContractID string) (*Response, error)

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 Uses

func (client *Client) GetSmartContractSecret(secretName string) (_ string, err error)

GetSmartContractSecret pulls a secret for the running smart contract from the chain.

func (*Client) GetStatus Uses

func (client *Client) GetStatus() (*Response, error)

GetStatus returns the chain's status, such as Active or Updating.

func (*Client) GetTransaction Uses

func (client *Client) GetTransaction(txnID string) (*Response, error)

GetTransaction gets a transaction from the chain by id.

func (*Client) GetTransactionType Uses

func (client *Client) GetTransactionType(transactionType string) (*Response, error)

GetTransactionType returns a transaction type on chain by its name.

func (*Client) GetVerifications Uses

func (client *Client) GetVerifications(blockID string, level int) (*Response, error)

GetVerifications returns a block's verification at a specific level of DragonNet.

func (*Client) ListAPIKeys Uses

func (client *Client) ListAPIKeys() (*Response, error)

ListAPIKeys for a chain.

func (*Client) ListSmartContractObjects Uses

func (client *Client) ListSmartContractObjects(folder, smartContractID string) (*Response, error)

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 Uses

func (client *Client) ListTransactionTypes() (*Response, error)

ListTransactionTypes lists out all registered transaction types for a chain.

func (*Client) QueryBlocks Uses

func (client *Client) QueryBlocks(query *Query) (*Response, error)

QueryBlocks gets all blocks matching the given query.

func (*Client) QuerySmartContracts Uses

func (client *Client) QuerySmartContracts(query *Query) (*Response, error)

QuerySmartContracts returns a list of matching contracts on the chain.

func (*Client) QueryTransactions Uses

func (client *Client) QueryTransactions(query *Query) (*Response, error)

QueryTransactions gets all transactions matching the given query on the chain.

func (*Client) UpdateSmartContract Uses

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 Uses

func (client *Client) UpdateTransactionType(transactionType string, customIndexes []CustomIndexStructure) (*Response, error)

UpdateTransactionType updates a given transaction type.

type Configuration Uses

type Configuration struct {
    DefaultDcID string
    AuthKeys    map[string]*AuthKey

Configuration defines the SDK configuration of chainID and AuthKeys.

func GetCredentialConfigs Uses

func GetCredentialConfigs() (*Configuration, error)

GetCredentialConfigs returns

type Contract Uses

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 Uses

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 Uses

type ContractStatus struct {
    State     string `json:"state"`
    Msg       string `json:"msg"`
    Timestamp string `json:"timestamp"`

ContractStatus defines the status object for contracts.

type CreateTransaction Uses

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 Uses

type Credentials struct {
    // contains filtered or unexported fields

Credentials implements the Authenticator interface to generate authentication headers.

func NewCredentials Uses

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 Uses

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 Uses

func (creds *Credentials) GetDragonchainID() string

GetDragonchainID returns the current chain's ID.

type CustomIndexStructure Uses

type CustomIndexStructure struct {
    Key  string `json:"key"`
    Path string `json:"path"`

CustomIndexStructure defines the valid format of custom indexes on a transaction type.

type ErrFailedRequest Uses

type ErrFailedRequest struct {
    Status  int    `json:"status"`
    Message string `json:"message"`

ErrFailedRequest defines the structure of an error returned by the chain.

func NewRequestError Uses

func NewRequestError(resp *http.Response) *ErrFailedRequest

NewRequestError returns a formatted ErrFailedRequest object from the chain's http response.

func (ErrFailedRequest) Error Uses

func (err ErrFailedRequest) Error() string

type EthereumTransaction Uses

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 GetSmartContractHeap Uses

type GetSmartContractHeap struct {
    SCName string `json:"sc_name"`
    Key    string `json:"key"`

GetSmartContractHeap defines the request format for getting a key from a Smart Contract's heap.

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 Uses

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 Uses

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 Uses

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 Uses

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 Proof Uses

type Proof struct {
    Full     string `json:"full"`
    Stripped string `json:"stripped"`

Proof defines the proof object returned by L1 dragonchains.

type Query Uses

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.

func NewQuery Uses

func NewQuery(query, sort string, offset int, limit int) (*Query, error)

NewQuery constructs a Query based on provided parameters.

type Response Uses

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 Uses

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 Uses

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.

type Verification Uses

type Verification struct {
    L2  []Block `json:"2,omitempty"`
    L3  []Block `json:"3,omitempty"`
    L4  []Block `json:"4,omitempty"`
    L5  []Block `json:"5,omitempty"`

Verification is a representation of the verification object for a block.

Package dragonchain imports 22 packages (graph). Updated 2020-02-07. Refresh now. Tools for package owners.