stacks

package module
v0.0.0-...-61460eb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 22 Imported by: 0

README

stacks-sdk

Stacks SDK is used to interact with the Stacks blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/okx/go-wallet-sdk/coins/stacks

Usage

New Address
	priKey := "598d99970d04be67e8b41ddd5c5453487eeab5345ea1638c9a2849dee377f2a301"
	addr, err := NewAddress(priKey)
	if err != nil {
		// todo
	}
Transfer
	result, err := Transfer("598d99970d04be67e8b41ddd5c5453487eeab5345ea1638c9a2849dee377f2a3", "SP2P58SJY1XH6GX4W3YGEPZ2058DD3JHBPJ8W843Q", "20", big.NewInt(3000), big.NewInt(8), big.NewInt(200))
	if err != nil {
		// todo
	}

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

View Source
const (
	SerializeP2PKH  = 0
	SerializeP2SH   = 1
	SerializeP2WPKH = 2
	SerializeP2WSH  = 3
)
View Source
const (
	Int               = 0
	Uint              = 1
	Buffer            = 2
	BoolTrue          = 3
	BoolFalse         = 4
	PrincipalStandard = 5
	PrincipalContract = 6
	ResponseOk        = 7
	ResponseErr       = 8
	OptionalNone      = 9
	OptionalSome      = 10
	List              = 11
	Tuple             = 12
	IntASCII          = 13
	IntUTF8           = 14
)
View Source
const (
	ADDRESS              = 0
	PRINCIPAL            = 1
	LENGTHPREFIXEDSTRING = 2
	MEMOSTRING           = 3
	ASSETINFO            = 4
	POSTCONDITION        = 5
	PUBLICKEY            = 6
	LENGTHPREFIXEDLIST   = 7
	PAYLOAD              = 8
	MESSAGESIGNATURE     = 9
	TRANSACTIONAUTHFIELD = 10
)
View Source
const (
	PostConditionModeAllow = 1
	PostConditionModeDeny  = 2
)
View Source
const (
	PostConditionPrincipalIDORIGIN   = 1
	PostConditionPrincipalIDSTANDARD = 2
	PostConditionPrincipalIDCONTRACT = 3
)
View Source
const (
	Origin   = 0x01
	Standard = 0x02
	Contract = 0x03
)
View Source
const (
	STX         = 0x00
	Fungible    = 0x01
	NonFungible = 0x02
)
View Source
const (
	MaxBufferSize = 1024 * 4
)

Variables

This section is empty.

Functions

func BigToHex

func BigToHex(in *big.Int) string

func ContractCall

func ContractCall(senderKey string, from string, to string, memo string, amount *big.Int, contractAddress, contractName, tokenName, functionName string, nonce, fee *big.Int) (string, error)

func GetAddressFromPublicKey

func GetAddressFromPublicKey(pubKey string) (string, error)

func GetPublicKey

func GetPublicKey(privKeyHex string) (string, error)

func NewAddress

func NewAddress(privKeyHex string) (string, error)

func Serialize

func Serialize(stacksTransaction StacksTransaction) []byte

func SerializePayload

func SerializePayload(payload Payload) []byte

func Stack

func Stack(contractAddress, contractName, functionName, poxAddress string, amount, height, cycle *big.Int, senderKey string, nonce, fee *big.Int) (string, error)

Stack Deprecated

func Transfer

func Transfer(privateKey string, to string, memo string, amount *big.Int, nonce *big.Int, fee *big.Int) (string, error)

func Txid

func Txid(stacksTransaction StacksTransaction) string

func ValidAddress

func ValidAddress(address string) bool

Types

type Address

type Address struct {
	Type_   uint32 `json:"type"`
	Version uint64 `json:"version"`
	Hash160 string `json:"hash160"`
}

func (Address) GetType

func (a Address) GetType() int

type AssetInfo

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

type BooleanCV

type BooleanCV struct {
	Type_ int `json:"type"`
}

func (BooleanCV) GetType

func (b BooleanCV) GetType() int

type BufferCV

type BufferCV struct {
	Type_  int    `json:"type"`
	Buffer []byte `json:"buffer"`
}

func (BufferCV) GetType

func (b BufferCV) GetType() int

type BytesReader

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

func NewBytesReader

func NewBytesReader(arr []byte) *BytesReader

func (*BytesReader) ReadBytes

func (br *BytesReader) ReadBytes(length int) []byte

func (*BytesReader) ReadUInt8

func (br *BytesReader) ReadUInt8() uint8

type ClarityValue

type ClarityValue interface {
	Message
}

func DeserializeCV

func DeserializeCV(serializedClarityValue string) ClarityValue

func DeserializeJson

func DeserializeJson(args []interface{}) []ClarityValue

func NewUntilBurnBlockHeight

func NewUntilBurnBlockHeight(untilBurnBlockHeight *big.Int) ClarityValue

type ContractCallPayload

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

func CreateContractCallPayload

func CreateContractCallPayload(contractAddress, contractName, functionName string, functionArgs []ClarityValue) *ContractCallPayload

type ContractPrincipal

type ContractPrincipal struct {
	PostConditionPrincipal
	// contains filtered or unexported fields
}

type ContractPrincipalCV

type ContractPrincipalCV struct {
	Type_        int                  `json:"type"`
	Address      Address              `json:"address"`
	ContractName LengthPrefixedString `json:"contractName"`
}

func NewContractPrincipalCV

func NewContractPrincipalCV(principal string) (*ContractPrincipalCV, error)

func (ContractPrincipalCV) GetType

func (c ContractPrincipalCV) GetType() int

type DecodeBtcAddressBean

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

type FungiblePostCondition

type FungiblePostCondition struct {
	PostCondition
	// contains filtered or unexported fields
}

func (FungiblePostCondition) GetType

func (f FungiblePostCondition) GetType() int

type IntCV

type IntCV struct {
	Type_ int      `json:"type"`
	Value *big.Int `json:"value"`
}

func NewIntCV

func NewIntCV(value *big.Int) *IntCV

func (IntCV) GetType

func (i IntCV) GetType() int

type KeyValuePair

type KeyValuePair struct {
	Name  string
	Value ClarityValue
}

type LPList

type LPList struct {
	Type              int                      `json:"type"`
	LengthPrefixBytes int                      `json:"lengthPrefixBytes"`
	Values            []PostConditionInterface `json:"values"`
}

type LegacyAddress

type LegacyAddress struct {
	Bytes []byte
	P2sh  bool
}

func FromBase58

func FromBase58(b58 string) (*LegacyAddress, error)

type LengthPrefixedString

type LengthPrefixedString struct {
	Content           string `json:"content"`
	LengthPrefixBytes int    `json:"lengthPrefixBytes"`
	MaxLengthBytes    int    `json:"maxLengthBytes"`
	Type              int    `json:"type"`
}

func (LengthPrefixedString) GetType

func (l LengthPrefixedString) GetType() int

type ListCV

type ListCV struct {
	Type_ int            `json:"type"`
	List  []ClarityValue `json:"list"`
}

func (ListCV) GetType

func (l ListCV) GetType() int

type Memo

type Memo struct {
	Type_   uint32 `json:"type"`
	Content string `json:"content"`
}

func (Memo) GetType

func (m Memo) GetType() int

type Message

type Message interface {
	GetType() int
}

type MessageSignature

type MessageSignature struct {
	Type_ uint64 `json:"type"`
	Data  string `json:"data"`
}

type NextSignature

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

type NoneCV

type NoneCV struct {
	Type_ int
}

func (NoneCV) GetType

func (n NoneCV) GetType() int

type Payload

type Payload interface {
	// contains filtered or unexported methods
}

type PostCondition

type PostCondition struct {
	StacksMessage
	ConditionType int
	// Principal     PostConditionPrincipal
	Principal     PostConditionPrincipalInterface
	ConditionCode int
}

func (PostCondition) GetType

func (p PostCondition) GetType() int

type PostConditionInterface

type PostConditionInterface interface {
	Message
	// contains filtered or unexported methods
}

func DeserializePostCondition

func DeserializePostCondition(postCondition string) PostConditionInterface

type PostConditionPrincipal

type PostConditionPrincipal struct {
	Type    int
	Prefix  int
	Address Address
}

type PostConditionPrincipalInterface

type PostConditionPrincipalInterface interface {
	// contains filtered or unexported methods
}

type PrincipalCV

type PrincipalCV struct {
	Address Address `json:"address"`
	Type_   uint32  `json:"Type_"`
}

type ResponseCV

type ResponseCV struct {
	Type_ int          `json:"type"`
	Value ClarityValue `json:"value"`
}

func (ResponseCV) GetType

func (r ResponseCV) GetType() int

type STXPostCondition

type STXPostCondition struct {
	PostCondition
	// contains filtered or unexported fields
}

func (STXPostCondition) GetType

func (s STXPostCondition) GetType() int

type SignedContractCallOptions

type SignedContractCallOptions struct {
	ContractAddress         string                   `json:"contractAddress"`
	ContractName            string                   `json:"contractName"`
	FunctionName            string                   `json:"functionName"`
	FunctionArgs            []ClarityValue           `json:"functionArgs"`
	SendKey                 string                   `json:"sendKey"`
	ValidateWithAbi         bool                     `json:"validateWithAbi"`
	Fee                     big.Int                  `json:"fee"`
	Nonce                   big.Int                  `json:"nonce"`
	AnchorMode              int                      `json:"anchorMode"`
	PostConditionMode       int                      `json:"postConditionMode"`
	PostConditions          []PostConditionInterface `json:"postConditions"`
	SerializePostConditions []string                 `json:"serializePostConditions"`
}

type SignedTokenTransferOptions

type SignedTokenTransferOptions struct {
	Recipient string  `json:"recipient"`
	Amount    big.Int `json:"amount"`
	Fee       big.Int `json:"fee"`
	Nonce     big.Int `json:"nonce"`
	Memo      string  `json:"memo"`
	SenderKey string  `json:"senderKey"`
}

type Signer

type Signer struct {
	Type_   uint64 `json:"type"`
	Version uint64 `json:"version"`
	Hash160 string `json:"hash160"`
}

type SingleSigSpendingCondition

type SingleSigSpendingCondition struct {
	HashMode    uint64           `json:"hashMode"`
	Signer      string           `json:"signer"`
	Nonce       big.Int          `json:"nonce"`
	Fee         big.Int          `json:"fee"`
	KeyEncoding uint64           `json:"keyEncoding"`
	Signature   MessageSignature `json:"signature"`
}

type SomeCV

type SomeCV struct {
	Type_ int          `json:"type"`
	Value ClarityValue `json:"value"`
}

func (SomeCV) GetType

func (s SomeCV) GetType() int

type StacksMessage

type StacksMessage struct {
	Type int `json:"type"`
}

type StacksPrivateKey

type StacksPrivateKey struct {
	Data       []byte
	Compressed bool
}

type StacksPublicKey

type StacksPublicKey struct {
	Type_ uint64 `json:"type"`
	Data  string `json:"data"`
}

type StacksTransaction

type StacksTransaction struct {
	Version           int                   `json:"version"`
	ChainId           int64                 `json:"chainId"`
	Auth              StandardAuthorization `json:"auth"`
	AnchorMode        int                   `json:"anchorMode"`
	Payload           Payload               `json:"payload"`
	PostConditionMode int                   `json:"postConditionMode"`
	PostConditions    LPList                `json:"postConditions"`
}

func MakeContractCall

func MakeContractCall(txOptions *SignedContractCallOptions) (*StacksTransaction, error)

type StacksTransferSig

type StacksTransferSig struct {
	Version   uint8  `json:"version"`
	Nonce     uint64 `json:"nonce"`
	Recipient string `json:"recipient"`
	Amount    uint64 `json:"amount"`
	Fee       uint64 `json:"fee"`
	Memo      string `json:"memo"`
}

type StandardAuthorization

type StandardAuthorization struct {
	AuthType                 uint64                      `json:"authType"`
	SpendingCondition        *SingleSigSpendingCondition `json:"spendingCondition"`
	SponsorSpendingCondition *SingleSigSpendingCondition `json:"sponsorSpendingCondition"`
}

type StandardPrincipalCV

type StandardPrincipalCV struct {
	Address *Address `json:"address"`
	Type_   int      `json:"type"`
}

func NewStandardPrincipalCV

func NewStandardPrincipalCV(address string) *StandardPrincipalCV

func (StandardPrincipalCV) GetType

func (s StandardPrincipalCV) GetType() int

type StringCV

type StringCV struct {
	Type_ int    `json:"type"`
	Data  string `json:"data"`
}

func (StringCV) GetType

func (s StringCV) GetType() int

type TokenTransferPayload

type TokenTransferPayload struct {
	Type_       int                  `json:"type"`
	PayloadType int                  `json:"payloadType"`
	Recipient   *StandardPrincipalCV `json:"recipient"`
	Amount      big.Int              `json:"amount"`
	Memo        *Memo                `json:"memo"`
}

func CreateTokenTransferPayload

func CreateTokenTransferPayload(recipientCV string, amount big.Int, memo string) (*TokenTransferPayload, error)

type TransactionRes

type TransactionRes struct {
	TxId        string `json:"txId"`
	TxSerialize string `json:"txSerialize"`
}

type TransactionSigner

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

type TupleCV

type TupleCV struct {
	Type int                     `json:"type"`
	Data map[string]ClarityValue `json:"data"`
}

func GetPoxAddress

func GetPoxAddress(poxAddress string) (*TupleCV, error)

func (TupleCV) GetType

func (t TupleCV) GetType() int

type TupleData

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

type UintCV

type UintCV struct {
	Type_ int      `json:"type"`
	Value *big.Int `json:"value"`
}

func NewUintCV

func NewUintCV(value *big.Int) *UintCV

func (UintCV) GetType

func (u UintCV) GetType() int

Jump to

Keyboard shortcuts

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