kin

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 26 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// KinAssetCode is the asset code for Kin 2
	KinAssetCode = "KIN"

	// kin2ProdIssuer is the Kin 2 issuer address on the production Kin 2 network
	Kin2ProdIssuer = "GDF42M3IPERQCBLWFEZKQRK77JQ65SCKTU3CW36HZVCX7XX5A5QXZIVK"
	// kin2TestIssuer is the Kin 2 issuer address on the test Kin 2 network
	Kin2TestIssuer = "GBC3SG6NGTSZ2OMH3FFGB7UVRQWILW367U4GSOOF4TFSZONV42UJXUH7"
)
View Source
const HighestVersion = 1

HighestVersion is the highest 'supported' memo version by the implementation.

View Source
const MaxTransactionType = TransactionTypeP2P

MaxTransactionType is the maximum transaction type 'supported' by the implementation.

Variables

View Source
var (
	// ErrInvalidKinNetwork occurs when an invalid KinNetwork is provided
	ErrInvalidKinNetwork = errors.New("KinNetwork was not 'mainnet' or 'testnet'")
)

Functions

func AccountIDFromPublicKey added in v0.67.0

func AccountIDFromPublicKey(k PublicKey) xdr.AccountId

func AppIDFromTextMemo added in v0.76.0

func AppIDFromTextMemo(memo string) (appID string, ok bool)

AppIDFromTextMemo returns the canonical string AppID given a memo string.

If the provided memo is in the incorrect format, ok will be false.

func FromQuarks added in v0.67.0

func FromQuarks(amount int64) string

FromQuarks converts an int64 amount of quarks to the string representation of kin.

func GetClient

func GetClient() (client *horizon.Client, err error)

GetClient returns the default Horizon client based on which environment the application is running in.

func GetClientByKinNetwork

func GetClientByKinNetwork(net network.KinNetwork) (client *horizon.Client, err error)

GetClientByKinNetwork returns a Horizon client for the provided Kin network

func GetClientV2

func GetClientV2() (client *horizonclient.Client, err error)

GetClientV2 returns the default stellar based Horizon client based on which environment the application is running in.

The stellar based client offers some additional niceties, notably around retrieving transaction history. It's generally considered to be a better client, however, the functionality _may_ have some divergent behaviour from the kin fork. Therefore, any use of this client should be tested thoroughly.

func GetKin2Client added in v0.40.0

func GetKin2Client() (client *horizon.Client, err error)

GetKin2Client returns the default Kin 2 Horizon client based on which environment the environment is running in

func GetKin2ClientV2 added in v0.40.0

func GetKin2ClientV2() (client *horizonclient.Client, err error)

GetKin2ClientV2 returns the default stellar-based Kin 2 Horizon client based on which environment the application is running in.

The stellar based client offers some additional niceties, notably around retrieving transaction history. It's generally considered to be a better client, however, the functionality _may_ have some divergent behaviour from the kin fork. Therefore, any use of this client should be tested thoroughly.

func GetKin2Issuer added in v0.40.0

func GetKin2Issuer() (issuer string, err error)

GetKin2Issuer returns the Kin issuer address based on which environment the application is running in.

func GetKin2Network added in v0.40.0

func GetKin2Network() (network build.Network, err error)

GetKin2Network returns the default Kin 2 Network modifier based on which environment the application is running in.

func GetNetwork

func GetNetwork() (network build.Network, err error)

GetNetwork returns the default Network modifier based on which environment the application is running in.

func GetNetworkByKinNetwork

func GetNetworkByKinNetwork(net network.KinNetwork) (buildNetwork build.Network, err error)

GetNetworkByKinNetwork returns a Network modifier for the provided Kin network

func IsValidAppID added in v0.76.0

func IsValidAppID(appID string) bool

IsValidAppID returns whether or not the provided string is a valid app ID.

func IsValidMemo

func IsValidMemo(m Memo) bool

IsValidMemo returns whether or not the memo is valid.

It should be noted that there are no guarantees if the memo is valid, only if the memo is invalid. That is, this function may return false positives.

Stricter validation can be done via the IsValidMemoStrict. However, IsValidMemoStrict is not as forward compatible as IsValidMemo.

func IsValidMemoStrict

func IsValidMemoStrict(m Memo) bool

IsValidMemoStrict returns whether or not the memo is valid checking against this SDKs supported version and transaction types.

It should be noted that there are no guarantees if the memo is valid, only if the memo is invalid. That is, this function may return false positives.

func MustToQuarks added in v0.67.0

func MustToQuarks(val string) int64

MustToQuarks calls ToQuarks, panicking if there's an error.

This should only be used if you know for sure this will not panic.

func ToQuarks added in v0.67.0

func ToQuarks(val string) (int64, error)

ToQuarks converts a string representation of kin the quark value.

An error is returned if the value string is invalid, or it cannot be accurately represented as quarks. For example, a value smaller than quarks, or a value _far_ greater than the supply.

Types

type Creation added in v0.76.0

type Memo

type Memo [32]byte

Memo is the 32 byte memo encoded into transactions, as defined in github.com/kinecosystem/agora-api.

func MemoFromBase64String added in v0.45.0

func MemoFromBase64String(b64 string, strict bool) (m Memo, err error)

func MemoFromXDR

func MemoFromXDR(xm xdr.Memo, strict bool) (m Memo, ok bool)

MemoFromXDR returns a Memo from an xdr.Memo, provided it is a valid (or strictly valid) memo.

func MemoFromXDRString

func MemoFromXDRString(b64 string, strict bool) (m Memo, err error)

MemoFromXDRString returns a Memo from a standard base64 encoded xdr.Memo, provided it is valid (or strictly) valid memo.

func NewMemo

func NewMemo(v byte, t TransactionType, appIndex uint16, foreignKey []byte) (m Memo, err error)

NewMemo creates a new Memo with the specified parameters.

func (Memo) AppIndex

func (m Memo) AppIndex() uint16

AppIndex returns the app index of the memo.

func (Memo) ForeignKey

func (m Memo) ForeignKey() (fk []byte)

ForeignKey returns the foreign key of the memo.

func (Memo) TransactionType

func (m Memo) TransactionType() TransactionType

TransactionType returns the transaction type of the memo.

func (Memo) TransactionTypeRaw

func (m Memo) TransactionTypeRaw() TransactionType

TransactionTypeRaw returns the transaction type of the memo, even if it is unsupported by this SDK. It should only be used as a fall back if the raw value is needed when TransactionType() yields TransactionTypeUnknown.

func (Memo) Version

func (m Memo) Version() byte

Version returns the version of the memo.

type PrivateKey added in v0.67.0

type PrivateKey ed25519.PrivateKey

PrivateKey is an ed25519.PrivateKey.

func NewPrivateKey added in v0.67.0

func NewPrivateKey() (PrivateKey, error)

NewPrivateKey returns a new PrivateKey from derived from crypto/rand. The public key can be accessed via key.Public().

func PrivateKeyFromString added in v0.67.0

func PrivateKeyFromString(seed string) (PrivateKey, error)

PrivateKeyFromString parses a provided address, returning a PublicKey if successful.

The address may be either a Stellar encoded seed, or a base58 encoded string.

func (PrivateKey) Base58 added in v0.67.0

func (k PrivateKey) Base58() string

Base58 returns the base58-encoded private key

func (PrivateKey) Public added in v0.67.0

func (k PrivateKey) Public() PublicKey

Public returns the corresponding PublicKey.

func (PrivateKey) StellarSeed added in v0.67.0

func (k PrivateKey) StellarSeed() string

type PublicKey added in v0.67.0

type PublicKey ed25519.PublicKey

PublicKey is an ed25519.PublicKey.

func PublicKeyFromStellarXDR added in v0.67.0

func PublicKeyFromStellarXDR(id xdr.AccountId) (PublicKey, error)

func PublicKeyFromString added in v0.67.0

func PublicKeyFromString(address string) (PublicKey, error)

PublicKeyFromString parses a provided address, returning a PublicKey if successful.

The address may be either a Stellar encoded address, or a base58 encoded string.

func (PublicKey) Base58 added in v0.67.0

func (k PublicKey) Base58() string

Base58 returns the base58-encoded public key

func (PublicKey) StellarAddress added in v0.67.0

func (k PublicKey) StellarAddress() string

StellarAddress returns the stellar address representation of the public key.

type Region added in v0.76.0

type Region struct {
	MemoData []byte
	Memo     *Memo

	Creations []Creation
	Transfers []*token.DecompiledTransfer
	Closures  []*token.DecompiledCloseAccount
}

Region is an abstract 'region' within a transaction.

See the documentation for SignTransaction in the transaction service API.

type TransactionType

type TransactionType int16

TransactionType is the memo transaction type.

const (
	TransactionTypeUnknown TransactionType = iota - 1
	TransactionTypeNone
	TransactionTypeEarn
	TransactionTypeSpend
	TransactionTypeP2P
)

type Tx added in v0.76.0

type Tx struct {
	AppIndex uint16
	AppID    string

	AdvanceNonce *system.DecompiledAdvanceNonce

	Regions []Region
}

Tx represents a parsed kin solana transaction

func ParseTransaction added in v0.76.0

func ParseTransaction(
	tx solana.Transaction,
	il *commonpb.InvoiceList,
) (parsed Tx, err error)

ParseTransaction parses a (solana transaction, invoice list) pair.

The following invariants are checked while parsing:

  1. Each instruction is one of the following: - Memo::Memo - System::CreateAccount - System::AdvanceNonce - SplToken::InitializeAccount - SplAssociatedToken::CreateAssociatedAccount - SplToken::SetAuthority - SplToken::Transfer - SplToken::CloseAccount
  2. If an invoice is provided, it must match _exactly_ one region.
  3. Transfer instructions cannot use the subsidizer as a source.
  4. SetAuthority can only be related to a newly created account.
  5. SetAuthority can only be of the types AccountHolder and CloseAccount.
  6. SetAuthority must be related to a SplToken::Initialize/SplAssociatedToken::CreateAssociatedAccount instruction.
  7. There cannot be multiple values (excluding none) of AppIndex or AppID. - The link between AppIndex and AppID is not validated.
  8. Earns cannot be mixed with P2P/Spend payments.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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