core

package module
v0.0.0-...-2230e26 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 25 Imported by: 0

README

The Go SDK for the Abelian Blockchain

GitHub Release Made with Java

A Go library that allows developers to interact with the Abelian blockchain.

It provides low-level APIs to interact with the Abelian blockchain including creating keys and addresses, querying blockchain data, decoding privacy-protected data, building transactions, signing transactions and sending transactions.

Please refer to A Demo Application of the Abelian Go SDK for the following topics:

  • How to build and run the demo application.
  • How to interact with the Abelian blockchain using the demo application only (without the need to write any code).
  • How to integrate the SDK into your project and the usage of the SDK.

For high-level APIs, please refer to the Abelian Java SDK which is built on top of this Go SDK.

Documentation

Index

Constants

View Source
const (
	COIN_ADDRESS_LENGTH       = 9504
	CRYPTO_ADDRESS_LENGTH     = 10696
	ABEL_ADDRESS_LENGTH       = 10729
	SHORT_ABEL_ADDRESS_LENGTH = 66
)
View Source
const (
	DEFAULT_CHAIN_ID = 0x00
)

Define constants.

Variables

View Source
var LOG = NewLogger("abelsdk")

Functions

func AbelToNeutrino

func AbelToNeutrino(abelAmount float64) int64

func DecodeValueFromTxOutData

func DecodeValueFromTxOutData(txOutData Bytes, viewSecretKey *CryptoKey) (int64, error)

func GenerateCryptoSeedFromMnemonic

func GenerateCryptoSeedFromMnemonic(mnemonic []string, sequenceNumber uint64) ([]byte, error)

func GenerateRandomMnemonic

func GenerateRandomMnemonic() ([]string, error)

func GetRingBlockHeights

func GetRingBlockHeights(height int64) []int64

Define util functions.

func NeutrinoToAbel

func NeutrinoToAbel(neutrinoAmount int64) float64

Define util functions.

Types

type AbecBlock

type AbecBlock struct {
	Height        int64     `json:"height"`
	Confirmations int64     `json:"confirmations"`
	Version       int64     `json:"version"`
	VersionHex    string    `json:"versionHex"`
	Time          int64     `json:"time"`
	Nonce         uint64    `json:"nonce"`
	Size          int64     `json:"size"`
	FullSize      int64     `json:"fullsize"`
	Difficulty    float64   `json:"difficulty"`
	BlockHash     string    `json:"hash"`
	PrevBlockHash string    `json:"previousblockhash"`
	NextBlockHash string    `json:"nextblockhash"`
	ContentHash   string    `json:"contenthash"`
	MerkleRoot    string    `json:"merkleroot"`
	Bits          string    `json:"bits"`
	SealHash      string    `json:"sealhash"`
	Mixdigest     string    `json:"mixdigest"`
	TxHashes      []string  `json:"tx"`
	RawTxs        []*AbecTx `json:"rawTx"`
}

type AbecChainInfo

type AbecChainInfo struct {
	NumBlocks       int64   `json:"blocks"`
	IsTestnet       bool    `json:"testnet"`
	Version         int64   `json:"version"`
	ProtocolVersion int64   `json:"protocolversion"`
	RelayFee        float64 `json:"relayfee"`
}

type AbecJSONRPCRequest

type AbecJSONRPCRequest struct {
	JSONRPC string        `json:"jsonrpc"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
	ID      string        `json:"id"`
}

type AbecJSONRPCResponse

type AbecJSONRPCResponse struct {
	Result json.RawMessage `json:"result"`
	Error  json.RawMessage `json:"error"`
	ID     string          `json:"id"`
}

type AbecMempool

type AbecMempool map[string]struct {
	Size             int64   `json:"size"`
	FullSize         int64   `json:"fullsize"`
	Fee              float64 `json:"fee"`
	Time             int64   `json:"time"`
	Height           int64   `json:"height"`
	StartingPriority float64 `json:"startingpriority"`
	CurrentPriority  float64 `json:"currentpriority"`
}

type AbecRPCClient

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

Define data types.

func NewAbecRPCClient

func NewAbecRPCClient(endpoint string, username string, password string) *AbecRPCClient

Define methods for AbecRPCClient.

func (*AbecRPCClient) GetBlock

func (client *AbecRPCClient) GetBlock(hash string) (Bytes, *AbecBlock, error)

func (*AbecRPCClient) GetBlockByHeight

func (client *AbecRPCClient) GetBlockByHeight(height int64) (Bytes, *AbecBlock, error)

func (*AbecRPCClient) GetBlockBytes

func (client *AbecRPCClient) GetBlockBytes(hash string) (Bytes, error)

func (*AbecRPCClient) GetBlockBytesByHeight

func (client *AbecRPCClient) GetBlockBytesByHeight(height int64) (Bytes, error)

func (*AbecRPCClient) GetBlockHash

func (client *AbecRPCClient) GetBlockHash(height int64) (Bytes, *string, error)

func (*AbecRPCClient) GetChainInfo

func (client *AbecRPCClient) GetChainInfo() (Bytes, *AbecChainInfo, error)

func (*AbecRPCClient) GetEstimatedTxFee

func (client *AbecRPCClient) GetEstimatedTxFee() int64

func (*AbecRPCClient) GetMempool

func (client *AbecRPCClient) GetMempool() (Bytes, *AbecMempool, error)

func (*AbecRPCClient) GetRawTx

func (client *AbecRPCClient) GetRawTx(hash string) (Bytes, *AbecTx, error)

func (*AbecRPCClient) GetTxBytes

func (client *AbecRPCClient) GetTxBytes(hash string) (Bytes, error)

func (*AbecRPCClient) SendRawTx

func (client *AbecRPCClient) SendRawTx(txStr string) (Bytes, *string, error)

type AbecTx

type AbecTx struct {
	Hex           string        `json:"hex"`
	TxID          string        `json:"txid"`
	TxHash        string        `json:"hash"`
	Time          int64         `json:"time"`
	BlockHash     string        `json:"blockhash"`
	BlockTime     int64         `json:"blocktime"`
	Confirmations int64         `bson:"confirmations"`
	Version       int64         `json:"version"`
	Size          int64         `json:"size"`
	FullSize      int64         `json:"fullsize"`
	Fee           float64       `json:"fee"`
	Witness       string        `json:"witness"`
	Vin           []*AbecTxVin  `json:"vin"`
	Vout          []*AbecTxVout `json:"vout"`
}

type AbecTxVin

type AbecTxVin struct {
	UTXORing     AbecUTXORing `json:"prevutxoring"`
	SerialNumber string       `json:"serialnumber"`
}

type AbecTxVout

type AbecTxVout struct {
	N      int64  `json:"n"`
	Script string `json:"script"`
}

type AbecUTXORing

type AbecUTXORing struct {
	Version     int64    `json:"version"`
	BlockHashes []string `json:"blockhashs"`
	OutPoints   []struct {
		TxHash string `json:"txid"`
		Index  int64  `json:"index"`
	} `json:"outpoints"`
}

type AbelAddress

type AbelAddress struct {
	Address
}

Define the AbelAddress data type.

func NewAbelAddress

func NewAbelAddress(data Bytes) *AbelAddress

Define methods for AbelAddress.

func NewAbelAddressFromCryptoAddress

func NewAbelAddressFromCryptoAddress(cryptoAddress *CryptoAddress, chainID ...int8) *AbelAddress

func (*AbelAddress) GetChainID

func (a *AbelAddress) GetChainID() int8

func (*AbelAddress) GetChecksum

func (a *AbelAddress) GetChecksum() Bytes

func (*AbelAddress) GetCryptoAddress

func (a *AbelAddress) GetCryptoAddress() *CryptoAddress

func (*AbelAddress) GetShortAbelAddress

func (a *AbelAddress) GetShortAbelAddress() *ShortAbelAddress

func (*AbelAddress) Validate

func (a *AbelAddress) Validate() error

type Address

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

Define the Address data type.

func NewAddress

func NewAddress(data Bytes, addressType AddressType, fingerprint ...Bytes) Address

Define methods for Address.

func (*Address) Data

func (a *Address) Data() Bytes

func (*Address) Fingerprint

func (a *Address) Fingerprint() Bytes

func (*Address) Hash

func (a *Address) Hash() Bytes

func (*Address) HexString

func (a *Address) HexString() string

func (Address) String

func (a Address) String() string

func (*Address) Type

func (a *Address) Type() AddressType

func (*Address) Validate

func (a *Address) Validate() error

type AddressType

type AddressType int

Define constants.

const (
	ANY_ADDRESS_TYPE AddressType = iota
	COIN_ADDRESS_TYPE
	CRYPTO_ADDRESS_TYPE
	ABEL_ADDRESS_TYPE
	SHORT_ABEL_ADDRESS_TYPE
)

func (AddressType) String

func (addressType AddressType) String() string

type Bytes

type Bytes []byte

Define data types.

func AbecRPCClientCallForResult

func AbecRPCClientCallForResult[ResultType any](client *AbecRPCClient, result *ResultType, method string, params []interface{}) (Bytes, *ResultType, error)

func AsBytes

func AsBytes(data []byte) Bytes

Define methods for Bytes.

func DecodeCoinSerialNumbers

func DecodeCoinSerialNumbers(coinIDs []*CoinID, serialNoSecretKeys []*CryptoKey, ringBlockDescs map[int64]*TxBlockDesc) ([]Bytes, error)

func GenerateSafeCryptoSeed

func GenerateSafeCryptoSeed() (Bytes, error)

Define wrapper methods for Abec APIs.

func MakeBytes

func MakeBytes(length int, capacity ...int) Bytes

func MakeBytesFromHexString

func MakeBytesFromHexString(hexString string) Bytes

func MakeRandomBytes

func MakeRandomBytes(length int, seed ...int64) Bytes

func (Bytes) Base64String

func (b Bytes) Base64String() string

func (Bytes) FillRandomData

func (b Bytes) FillRandomData(seed int64, alphabet string)

func (Bytes) HexString

func (b Bytes) HexString() string

func (Bytes) JSONUnmarshal

func (b Bytes) JSONUnmarshal(v any) error

func (Bytes) Len

func (b Bytes) Len() int

func (Bytes) Md5

func (b Bytes) Md5() Bytes

func (Bytes) Sha256

func (b Bytes) Sha256() Bytes

func (Bytes) Slice

func (b Bytes) Slice() []byte

func (Bytes) String

func (b Bytes) String() string

func (Bytes) Summary

func (b Bytes) Summary(verbosity int, affixLen ...int) string

type Coin

type Coin struct {
	ID                CoinID
	OwnerShortAddress *ShortAbelAddress
	OwnerAddress      *AbelAddress
	Value             int64
	SerialNumber      Bytes
	TxVoutData        Bytes
	BlockHash         Bytes
	BlockHeight       int64
}

type CoinAddress

type CoinAddress struct {
	Address
}

Define the CoinAddress data type.

func DecodeCoinAddressFromTxOutData

func DecodeCoinAddressFromTxOutData(txOutData Bytes) (*CoinAddress, error)

func NewCoinAddress

func NewCoinAddress(data Bytes) *CoinAddress

Define methods for CoinAddress.

func (*CoinAddress) Validate

func (a *CoinAddress) Validate() error

type CoinID

type CoinID struct {
	TxHash Bytes
	Index  uint8
}

Define the CoinID and Coin data types.

func NewCoinID

func NewCoinID(txHash Bytes, index uint8) *CoinID

Define methods for CoinID.

func (CoinID) String

func (id CoinID) String() string

type CryptoAddress

type CryptoAddress struct {
	Address
}

Define the CryptoAddress data type.

func NewCryptoAddress

func NewCryptoAddress(data Bytes) *CryptoAddress

Define methods for CryptoAddress.

func (*CryptoAddress) GetCoinAddress

func (a *CryptoAddress) GetCoinAddress() *CoinAddress

func (*CryptoAddress) Validate

func (a *CryptoAddress) Validate() error

type CryptoKey

type CryptoKey struct {
	Bytes
}

Define the CryptoKey data type.

func NewCryptoKey

func NewCryptoKey(data Bytes) *CryptoKey

Define methods for CryptoKey.

type CryptoKeysAndAddress

type CryptoKeysAndAddress struct {
	SpendSecretKey    CryptoKey
	SerialNoSecretKey CryptoKey
	ViewSecretKey     CryptoKey
	CryptoAddress     CryptoAddress
}

Define the CryptoKeysAndAddress data type.

func GenerateCryptoKeysAndAddress

func GenerateCryptoKeysAndAddress(cryptoSeed Bytes) (*CryptoKeysAndAddress, error)

type Logger

type Logger struct {
	*log.Logger
}

func NewLogger

func NewLogger(name string) *Logger

type ShortAbelAddress

type ShortAbelAddress struct {
	Address
}

Define the ShortAbelAddress data type.

func MakeShortAbelAddress

func MakeShortAbelAddress(fingerprint Bytes, cryptoAddressHash Bytes, chainID ...int8) *ShortAbelAddress

func NewShortAbelAddress

func NewShortAbelAddress(data Bytes) *ShortAbelAddress

Define methods for ShortAbelAddress.

func (*ShortAbelAddress) GetChainID

func (a *ShortAbelAddress) GetChainID() int8

func (*ShortAbelAddress) Validate

func (a *ShortAbelAddress) Validate() error

type SignedRawTx

type SignedRawTx struct {
	Bytes
	Txid Bytes
}

Define the SignedRawTx data type and methods.

func GenerateSignedRawTx

func GenerateSignedRawTx(unsignedRawTx *UnsignedRawTx, signerKeys []*CryptoKeysAndAddress) (*SignedRawTx, error)

func NewSignedRawTx

func NewSignedRawTx(data Bytes, txid Bytes) *SignedRawTx

type TxBlockDesc

type TxBlockDesc struct {
	BinData Bytes
	Height  int64
}

Define the TxBlockDesc data type and methods.

func NewTxBlockDesc

func NewTxBlockDesc(binData Bytes, height int64) *TxBlockDesc

type TxDesc

type TxDesc struct {
	TxInDescs        []*TxInDesc
	TxOutDescs       []*TxOutDesc
	TxFee            int64
	TxRingBlockDescs map[int64]*TxBlockDesc
}

Define the TxDesc data type and methods.

func NewTxDesc

func NewTxDesc(txInDescs []*TxInDesc, txOutDescs []*TxOutDesc, txFee int64, txRingBlockDescs map[int64]*TxBlockDesc) *TxDesc

type TxInDesc

type TxInDesc struct {
	TxOutData        Bytes
	CoinValue        int64
	Owner            *ShortAbelAddress
	Height           int64
	TxHash           Bytes
	TxOutIndex       uint8
	CoinSerialNumber Bytes
}

Define the TxInDesc data type and methods.

func NewTxInDesc

func NewTxInDesc(data Bytes, coinValue ...int64) *TxInDesc

func (*TxInDesc) GetCoinAddress

func (d *TxInDesc) GetCoinAddress() (*CoinAddress, error)

func (*TxInDesc) GetFingerprint

func (d *TxInDesc) GetFingerprint() Bytes

type TxOutDesc

type TxOutDesc struct {
	AbelAddress *AbelAddress
	CoinValue   int64
}

Define the TxOutDesc data type and methods.

func NewTxOutDesc

func NewTxOutDesc(abelAddress *AbelAddress, coinValue int64) *TxOutDesc

type TxSubmissionResult

type TxSubmissionResult struct {
	SignedRawTx    *SignedRawTx
	SubmissionTime int64
	Success        bool
	Error          string
}

Define the TxSubmissionResult data type and methods.

type UnsignedRawTx

type UnsignedRawTx struct {
	Bytes
	Signers []*ShortAbelAddress
}

Define the UnsignedRawTx data type and methods.

func GenerateUnsignedRawTx

func GenerateUnsignedRawTx(txDesc *TxDesc) (*UnsignedRawTx, error)

func NewUnsignedRawTx

func NewUnsignedRawTx(data Bytes, signers ...[]*ShortAbelAddress) *UnsignedRawTx

Jump to

Keyboard shortcuts

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