goVsysSdk

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: Unlicense Imports: 19 Imported by: 0

README

goVsysSdk

GoDoc

The golang library for V Systems Blockchain.

Warning

The full functionality of SDK is still under development. The API may not be stable, please use it at your own risk.

Installing

Use go get to retrieve the SDK sto add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/tachyon-protocol/goVsysSdk
Dependencies

The metadata of the SDK's dependencies can be found in the Go module file go.mod

usage example
  • Notice you need 202.0v in TestNetApi to success run this example.
    • Change the seed to your seed in TestNetApi. or make the balance of AUCvntTpQo39XBaGrx26459RZJsragYBCSj(sender address in the example) more than 202.0v.
package main

import (
	"github.com/tachyon-protocol/goVsysSdk"
	"fmt"
	"time"
)

func main(){
	const seed = "test_qpbw2c2dmru97k8fptrp4kyj768cg7y99jn8rzk5dbydgxchfebnpkayjxqybmhq"
	api:=goVsysSdk.NewPublicTestNetApi()
	sender :=api.NewAccountFromSeedAndNonceV2(seed,0)
	receiver :=api.NewAccountFromSeedAndNonceV2(seed,1)
	senderVsys:=api.MustGetAccountBalance(sender.GetAddress())
	if senderVsys<202.0*goVsysSdk.VsysAmountRate{
		fmt.Println("WARNGING: you need at least 202.0v to finish this example.")
		fmt.Println("=========================================================")
	}
	fmt.Println("example of send vsys to another account.")
	fmt.Println("=========================================================")
	fmt.Println("sender", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()))
	fmt.Println("receiver", receiver.GetAddress(),api.MustGetAccountBalanceString(receiver.GetAddress()))
	fmt.Println("height",api.MustGetBlockHeight())
	fmt.Println("start send 1 vsys from sender to receiver.")
	api.MustSendPaymentSimpleSync(sender, receiver.GetAddress(),1*goVsysSdk.VsysAmountRate)
	fmt.Println("after 1 vsys from sender to receiver.")
	fmt.Println("sender", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()))
	fmt.Println("receiver", receiver.GetAddress(),api.MustGetAccountBalanceString(receiver.GetAddress()))
	fmt.Println("=========================================================")

	fmt.Println("example of create a token contract")
	fmt.Println("=========================================================")
	resp1 := api.MustRegisterContractToken(goVsysSdk.RegisterContractTokenReq{
		Sender:              sender,
		Max:                 1e9,
		Unity:               1e9,
		TokenDescription:    "td_2f8w2zwzj6",
		ContractDescription: "cd_svyh2c9ax4",
	})
	api.MustWaitPaymentOkByTransactionResponse(resp1)
	TokenContractId := resp1.ContractId
	tokenId:= goVsysSdk.ContractId2TokenId(resp1.ContractId,0)
	fmt.Println("after create a token contract, tokenId",tokenId,"TokenContractId:",TokenContractId)
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of token issue for tokenId",tokenId)
	fmt.Println("=========================================================")
	resp2:=api.MustTokenIssue(goVsysSdk.TokenIssueReq{
		Sender:  sender,
		TokenId: tokenId,
		Amount:  int64(1e9),
	})
	api.MustWaitPaymentOkByTransactionResponse(resp2)
	fmt.Println("after token issue for tokenId",tokenId)
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of create a PaymentChannel contract for tokenId",tokenId)
	fmt.Println("=========================================================")
	resp3 := api.MustRegisterContractPaymentChannel(goVsysSdk.RegisterContractPaymentChannelReq{
		Sender:        sender,
		Vsys_token_id: tokenId,
	})
	api.MustWaitPaymentOkByTransactionResponse(resp3)
	PaymentChannelContractId := resp3.ContractId
	fmt.Println("after create a PaymentChannel contract, PaymentChannelContractId",PaymentChannelContractId)
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of token deposit from ",tokenId," to PaymentChannelContractId",PaymentChannelContractId)
	fmt.Println("=========================================================")
	resp4 := api.MustTokenDeposit(goVsysSdk.TokenDepositReq{
		Sender:            sender,
		TokenId:           tokenId,
		ReceiveAddress:    sender.GetAddress(),
		ReceiveContractId: PaymentChannelContractId,
		Amount:            3,
	})
	api.MustWaitPaymentOkByTransactionResponse(resp4)
	fmt.Println("after token deposit")
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of PaymentChannelCreateAndLoad PaymentChannelContractId:",PaymentChannelContractId,"receiver address",receiver.GetAddress())
	fmt.Println("=========================================================")
	resp5 := api.MustPaymentChannelCreateAndLoad(goVsysSdk.PaymentChannelCreateAndLoadReq{
		Sender:           sender,
		ContractId:       PaymentChannelContractId,
		RecipientAddress: receiver.GetAddress(),
		Amount:           3,
		TimeStamp:        time.Now().Add(time.Hour * 24).UnixNano(),
	})
	api.MustWaitPaymentOkByTransactionResponse(resp5)
	channelId := resp5.Id
	fmt.Println("after PaymentChannelCreateAndLoad channelId",channelId)
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of PaymentChannelGenerateSenderPaymentSignature (no api call) channelId",channelId)
	fmt.Println("=========================================================")
	paymentS := goVsysSdk.PaymentChannelGenerateSenderPaymentSignature(sender, channelId, 1)
	fmt.Println("after PaymentChannelGenerateSenderPaymentSignature channelId",channelId,"paymentS",paymentS)
	fmt.Println("=========================================================")

	fmt.Println("example of MustPaymentChannelCollect channelId",channelId)
	fmt.Println("=========================================================")
	resp6 := api.MustPaymentChannelCollect(goVsysSdk.PaymentChannelCollectReq{
		Receiver:              receiver,
		ContractId:           PaymentChannelContractId,
		ChannelId:             channelId,
		Amount:                1,
		Payment_signature_str: paymentS,
	})
	api.MustWaitPaymentOkByTransactionResponse(resp6)
	fmt.Println("after MustPaymentChannelCollect channelId",channelId,"paymentS",paymentS)
	fmt.Println("receiver vsys", receiver.GetAddress(),api.MustGetAccountBalanceString(receiver.GetAddress()),"token",api.MustGetContractTokenBalance(receiver.GetAddress(),tokenId))
	fmt.Println("=========================================================")

	fmt.Println("example of MustTokenWithdraw tokenId",tokenId,"receiver",receiver.GetAddress(),"PaymentChannelContractId",PaymentChannelContractId)
	fmt.Println("=========================================================")
	resp7 := api.MustTokenWithdraw(goVsysSdk.TokenWithdrawReq{
		Sender:            receiver,
		TokenId:           tokenId,
		ReceiveAddress:    receiver.GetAddress(),
		ReceiveContractId: PaymentChannelContractId,
		Amount:            1,
	})
	api.MustWaitPaymentOkByTransactionResponse(resp7)
	fmt.Println("after MustTokenWithdraw channelId",channelId,"paymentS",paymentS)
	fmt.Println("receiver vsys", receiver.GetAddress(),api.MustGetAccountBalanceString(receiver.GetAddress()),"token",api.MustGetContractTokenBalance(receiver.GetAddress(),tokenId))
	fmt.Println("=========================================================")
	fmt.Println("sender vsys", sender.GetAddress(),api.MustGetAccountBalanceString(sender.GetAddress()),"token",api.MustGetContractTokenBalance(sender.GetAddress(),tokenId))
}

output of above example

example of send vsys to another account.
=========================================================
sender AUCvntTpQo39XBaGrx26459RZJsragYBCSj 238.7v
receiver AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM 3.4v
height 13682383
start send 1 vsys from sender to receiver.
after 1 vsys from sender to receiver.
sender AUCvntTpQo39XBaGrx26459RZJsragYBCSj 237.6v
receiver AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM 4.4v
=========================================================
example of create a token contract
=========================================================
after create a token contract, tokenId TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq TokenContractId: CF7EVuokPpqYy6JEH9JR2BzhUAaGZv2CeKw
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 137.6v token 0
=========================================================
example of token issue for tokenId TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq
=========================================================
after token issue for tokenId TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 137.3v token 1000000000
=========================================================
example of create a PaymentChannel contract for tokenId TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq
=========================================================
after create a PaymentChannel contract, PaymentChannelContractId CF4Fya2CyAdaMrxtBMzydTKD2dX2kJ9f7Jv
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 37.3v token 1000000000
=========================================================
example of token deposit from  TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq  to PaymentChannelContractId CF4Fya2CyAdaMrxtBMzydTKD2dX2kJ9f7Jv
=========================================================
after token deposit
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 37v token 999999997
=========================================================
example of PaymentChannelCreateAndLoad PaymentChannelContractId: CF4Fya2CyAdaMrxtBMzydTKD2dX2kJ9f7Jv receiver address AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM
=========================================================
after PaymentChannelCreateAndLoad channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 36.7v token 999999997
=========================================================
example of PaymentChannelGenerateSenderPaymentSignature (no api call) channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ
=========================================================
after PaymentChannelGenerateSenderPaymentSignature channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ paymentS 7dxKicDVz11hSy77gGxWBWfGYKQhHyXmbKt4wX36yvYzBpwLHrhj8ze4N6wZRrN69byBnCZgHsCFEE8tHVD6bto
=========================================================
example of MustPaymentChannelCollect channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ
=========================================================
after MustPaymentChannelCollect channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ paymentS 7dxKicDVz11hSy77gGxWBWfGYKQhHyXmbKt4wX36yvYzBpwLHrhj8ze4N6wZRrN69byBnCZgHsCFEE8tHVD6bto
receiver vsys AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM 4.1v token 0
=========================================================
example of MustTokenWithdraw tokenId TWu5D99q1cnZS1FWSrTsUtgcEaawoHXu8QqHeBLHq receiver AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM PaymentChannelContractId CF4Fya2CyAdaMrxtBMzydTKD2dX2kJ9f7Jv
=========================================================
after MustTokenWithdraw channelId DA1CLjfJunKwqW6AhDrWJHZbVoiu7eAEyVAFtnpdZCwQ paymentS 7dxKicDVz11hSy77gGxWBWfGYKQhHyXmbKt4wX36yvYzBpwLHrhj8ze4N6wZRrN69byBnCZgHsCFEE8tHVD6bto
receiver vsys AU3CJrTHUEL386t25tq3AzL2r9EqNnRKmZM 3.8v token 1
=========================================================
sender vsys AUCvntTpQo39XBaGrx26459RZJsragYBCSj 36.7v token 999999997
License

This package is licensed under the Unlicense. See LICENSE for details.

Notice

Documentation

Index

Constants

View Source
const (

	// Fee
	VsysPrecision   int64 = 1e8
	ContractExecFee int64 = 3e7
	DefaultTxFee    int64 = 1e7
	DefaultFeeScale int16 = 100

	// Network
	Testnet NetType = 'T'
	Mainnet NetType = 'M'

	// TX_TYPE
	TxTypePayment          = 2
	TxTypeLease            = 3
	TxTypeCancelLease      = 4
	TxTypeMinting          = 5
	TxTypeContractRegister = 8
	TxTypeContractExecute  = 9

	//contract funcIdx variable
	ActionInit      = "init"
	ActionSupersede = "supersede"
	ActionIssue     = "issue"
	ActionDestroy   = "destroy"
	ActionSplit     = "split"
	ActionSend      = "send"
	ActionTransfer  = "transfer"
	ActionDeposit   = "deposit"
	ActionWithdraw  = "withdraw"

	// function index
	FuncidxSupersede     = 0
	FuncidxIssue         = 1
	FuncidxDestroy       = 2
	FuncidxSplit         = 3
	FuncidxSend          = 3
	FuncidxSendSplit     = 4
	FuncidxWithdraw      = 6
	FuncidxWithdrawSplit = 7
	FuncidxDeposit       = 5
	FuncidxDepositSplit  = 6
)
View Source
const (
	DeTypePublicKey       = 0x01
	DeTypeAddress         = 0x02
	DeTypeAmount          = 0x03
	DeTypeInt32           = 0x04
	DeTypeShortText       = 0x05
	DeTypeContractAccount = 0x06
	//DeTypeAccount         = 0x07 // Account is not a data entry, please use DeTypeAddress or DeTypeContractAccount
	DeTypeTokenId   = 0x08
	DeTypeTimeStamp = 0x09
	DeTypeBool      = 10
	DeTypeShortByte = 11
)
View Source
const ContractCodeLock = `` /* 824-byte string literal not displayed */
View Source
const ContractCodePaymentChannel = `` /* 2691-byte string literal not displayed */
View Source
const ContractCodeToken = "" /* 1186-byte string literal not displayed */
View Source
const ContractDescriptor = "" /* 570-byte string literal not displayed */
View Source
const ContractWithSplitDescriptor = "" /* 615-byte string literal not displayed */
View Source
const IpxAmountRate = 1e9
View Source
const IpxContractId = "CC8Jx8aLkKVQmzuHBWNnhCSkn1GBLcjZ32k"
View Source
const IpxTokenId = "TWZZfKFqcaNVe5TrphLRNEm5DQFnBRJMjDDByqv84"
View Source
const TokenContractWithSplit = "" /* 1272-byte string literal not displayed */
View Source
const TokenSendFeeVsys = 0.3
View Source
const VsysAmountRate = 1e8

Variables

This section is empty.

Functions

func Base58Decode

func Base58Decode(b string) (val []byte, ok bool)

func Base58Encode

func Base58Encode(b []byte) string

Encode encodes a byte slice to a modified base58 string.

func BuildSeedHash

func BuildSeedHash(seed string, nonce int) []byte

func ContractId2TokenId

func ContractId2TokenId(contractId string, tokenIndex int) string

func DecodeContractTexture

func DecodeContractTexture(data string) string

func FormatIpx

func FormatIpx(ipx int64) string

func FormatVsys

func FormatVsys(v int64) string

func HashChain

func HashChain(nonceSecret []byte) []byte

func IsErrTransactionNotInBlockChain

func IsErrTransactionNotInBlockChain(err error) bool

"Transaction is not in blockchain"

func IsValidateAddress

func IsValidateAddress(address string, network NetType) bool

IsValidateAddress checks if address valid

func IsValidatePhrase

func IsValidatePhrase(phrase string) bool

IsValidatePhrase checks if phrase valid

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func MustBase58Decode

func MustBase58Decode(b string) []byte

Decode decodes a modified base58 string to a byte slice.

func MustGenerateSeed

func MustGenerateSeed() string

MustGenerateSeed generates seed string

func PaymentChannelGenerateSenderPaymentSignature

func PaymentChannelGenerateSenderPaymentSignature(Sender *Account, ChannelId string, Amount int64) string

func PublicKeyToAddress

func PublicKeyToAddress(publicKey string, network NetType) string

PublicKeyToAddress return address with base58 encoded

func SharedKey

func SharedKey(secretKey []uint8, publicKey []uint8) []uint8

func Sign

func Sign(secretKey []uint8, msg []uint8, opt_random []uint8) []uint8

func SignMessage

func SignMessage(secretKey []uint8, msg []uint8, opt_random []uint8) []uint8

func TokenId2ContractId

func TokenId2ContractId(tokenId string) string

func Verify

func Verify(publicKey []uint8, msg []uint8, signature []uint8) int

Types

type Account

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

func GenerateKeyPair

func GenerateKeyPair(seed []byte) *Account

GenerateKeyPair generate Account using seed byte array

func InitAccount

func InitAccount(network NetType) *Account

InitAccount return account with network initiated

func (*Account) AccountSeed

func (acc *Account) AccountSeed() string

func (*Account) BuildCancelLeasing

func (acc *Account) BuildCancelLeasing(txId string) *Transaction

BuildCancelLeasing build Cancel transaction

func (*Account) BuildExecuteContract

func (acc *Account) BuildExecuteContract(contractId string, funcIdx int16, funcData []byte, attachment []byte) *Transaction

BuildExecuteContract build ExecuteContract transaction

func (*Account) BuildFromPrivateKey

func (acc *Account) BuildFromPrivateKey(privateKey string)

BuildFromPrivateKey build account using privateKey

func (*Account) BuildFromSeed

func (acc *Account) BuildFromSeed(seed string, nonce int)

BuildFromPrivateKey build account using seed and nonce

func (*Account) BuildLeasing

func (acc *Account) BuildLeasing(recipient string, amount int64) *Transaction

BuildLeasing build leasing transaction recipient should be address amount is in minimum unit

func (*Account) BuildPayment

func (acc *Account) BuildPayment(recipient string, amount int64, attachment []byte) *Transaction

BuildPayment build payment transaction recipient should be address amount is in minimum unit attachment can be empty

func (*Account) BuildPayment2

func (acc *Account) BuildPayment2(transaction *Transaction) *Transaction

func (*Account) BuildSendTokenTransaction

func (acc *Account) BuildSendTokenTransaction(tokenId string, recipient string, amount int64, isSplitSupported bool, attachment []byte) *Transaction

BuildExecuteContract build SendToken transaction

func (*Account) GetAddress

func (acc *Account) GetAddress() string

get account address string

func (*Account) PrivateKey

func (acc *Account) PrivateKey() string

get account privateKey string

func (*Account) PublicKey

func (acc *Account) PublicKey() string

get account publicKey string

func (*Account) SetNetwork

func (acc *Account) SetNetwork(network NetType)

func (*Account) SignData

func (acc *Account) SignData(data []byte) string

SignData sign data bytes and the output is base58 encoded data

func (*Account) VerifySignature

func (acc *Account) VerifySignature(data, signature []byte) bool

VerifySignature check if signature is correct

type ApiCallExecuteContractReq

type ApiCallExecuteContractReq struct {
	Sender     *Account
	ContractId string
	FuncIdx    int16
	FuncData   []byte
	Attachment []byte
}

type ApiCallRegisterContractReq

type ApiCallRegisterContractReq struct {
	Sender              *Account
	ContractCode        string
	ContractDescription string
	DataB               []byte // from DataEncoder{}
}

type ApiRespNodeStatus

type ApiRespNodeStatus struct {
	BlockchainHeight int64  `json:"blockchainHeight"`
	StateHeight      int64  `json:"stateHeight"`
	UpdatedDate      string `json:"updatedDate"`
	UpdatedTimestamp int64  `json:"updatedTimestamp"`
}

type Block

type Block struct {
	Version       int    `json:"version"`
	Timestamp     int64  `json:"timestamp"`
	Reference     string `json:"reference"`
	SPOSConsensus struct {
		MintTime    int64 `json:"mintTime"`
		MintBalance int64 `json:"mintBalance"`
	} `json:"SPOSConsensus"`
	ResourcePricingData struct {
		Computation  int64 `json:"computation"`
		Storage      int64 `json:"storage"`
		Memory       int64 `json:"memory"`
		RandomIO     int64 `json:"randomIO"`
		SequentialIO int64 `json:"sequentialIO"`
	} `json:"resourcePricingData"`
	TransactionMerkleRoot string               `json:"TransactionMerkleRoot"`
	Transactions          []HistoryTransaction `json:"transactions"`
	Generator             string               `json:"generator"`
	Signature             string               `json:"signature"`
	Fee                   int64                `json:"fee"`
	Blocksize             int64                `json:"blocksize"`
	Height                int64                `json:"height"`
	TransactionCount      int64                `json:"transaction count"`
}

type BuildPayment2Req

type BuildPayment2Req struct {
	Recipient string
	Amount    int64
}

type CommonResp

type CommonResp struct {
	Error   int    `json:"error"`
	Message string `json:"message"`
}

type Contract

type Contract struct {
	ContractId          string
	Contract            string
	Max                 int64
	Unity               int64
	TokenDescription    string
	ContractDescription string
	Amount              int64
	TokenIdx            int32 // const 0
	Recipient           string
	SenderPublicKey     string
	NewUnity            int64  // split newUnity
	NewIssuer           string // supersede newIssuer

	Textual   Textual // [init func, user defined func, stateVar]
	Functions []Func
}

func (*Contract) BuildDestroyData

func (c *Contract) BuildDestroyData() []byte

func (*Contract) BuildIssueData

func (c *Contract) BuildIssueData() []byte

func (*Contract) BuildRegisterData

func (c *Contract) BuildRegisterData() []byte

func (*Contract) BuildSendData

func (c *Contract) BuildSendData() []byte

func (*Contract) BuildSplitData

func (c *Contract) BuildSplitData() []byte

func (*Contract) DecodeDestroy

func (c *Contract) DecodeDestroy(data []byte)

func (*Contract) DecodeIssue

func (c *Contract) DecodeIssue(data []byte)

func (*Contract) DecodeRegister

func (c *Contract) DecodeRegister(data []byte)

func (*Contract) DecodeSend

func (c *Contract) DecodeSend(data []byte)

func (*Contract) DecodeSplit

func (c *Contract) DecodeSplit(data []byte)

func (*Contract) DecodeSupersede

func (c *Contract) DecodeSupersede(data []byte)

func (*Contract) DecodeTexture

func (c *Contract) DecodeTexture()

type ContractLockReq

type ContractLockReq struct {
	Sender     *Account
	ContractId string
	Timestamp  int64
}

type DataEncoder

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

func (*DataEncoder) Decode

func (de *DataEncoder) Decode(data []byte) (list []DataEntry)

func (*DataEncoder) Encode

func (de *DataEncoder) Encode(data interface{}, dataEntryType byte)

func (*DataEncoder) EncodeArgAmount

func (de *DataEncoder) EncodeArgAmount(amount int16)

func (*DataEncoder) Result

func (de *DataEncoder) Result() []byte

func (*DataEncoder) WriteAddress

func (de *DataEncoder) WriteAddress(address string)

func (*DataEncoder) WriteAmount

func (de *DataEncoder) WriteAmount(amount int64)

func (*DataEncoder) WriteContractAccount

func (de *DataEncoder) WriteContractAccount(contractId string)

func (*DataEncoder) WriteShortByte

func (de *DataEncoder) WriteShortByte(bytes []byte)

type DataEntry

type DataEntry struct {
	Type  int8
	Value interface{}
}

type Func

type Func struct {
	Name    string
	Args    []string
	RetArgs []string
}

type GetContractDataResp

type GetContractDataResp struct {
	ContractId string `json:"contractId"`
	Key        string `json:"key"`
	Height     int64  `json:"height"`
	DbName     string `json:"dbName"`
	DataType   string `json:"dataType"`
	ValueI     int64
	ValueS     string
}

type GetContractTokenBalanceResp

type GetContractTokenBalanceResp struct {
	Address string `json:"address"`
	TokenId string `json:"tokenId"`
	Balance int64  `json:"balance"`
	Unity   int    `json:"unity"`
}

type HistoryTransaction

type HistoryTransaction struct {
	Type      int     `json:"type,omitempty"` // TX_TYPE
	Id        string  `json:"id,omitempty"`
	Fee       int64   `json:"fee,omitempty"`
	FeeScale  int64   `json:"feeScale,omitempty"`
	Timestamp int64   `json:"timestamp,omitempty"`
	Proofs    []Proof `json:"proofs,omitempty"`

	Recipient  string `json:"recipient,omitempty"`
	Amount     int64  `json:"amount,omitempty"`
	Attachment string `json:"attachmen,omitempty"`

	ContractId    string      `json:"contractId,omitempty"`
	FunctionIndex int         `json:"functionIndex,omitempty"` // FuncidxSplit,...
	FunctionData  string      `json:"functionData,omitempty"`
	Contract      *HtContract `json:"contract,omitempty"`
	InitData      string      `json:"initData,omitempty"`
	Description   string      `json:"description,omitempty"`

	Status     string `json:"status,omitempty"`
	FeeCharged int    `json:"feeCharged,omitempty"`
	Height     int    `json:"height,omitempty"`

	CurrentBlockHeight int `json:"currentBlockHeight,omitempty"`
}

func (*HistoryTransaction) GetFirstSenderAddress

func (tran *HistoryTransaction) GetFirstSenderAddress() string

func (*HistoryTransaction) IsContractSend

func (ht *HistoryTransaction) IsContractSend() bool

func (*HistoryTransaction) MustDecodeContractSend

func (ht *HistoryTransaction) MustDecodeContractSend() HtContractSend

type HtContract

type HtContract struct {
	LanguageCode    string   `json:"languageCode,omitempty"`
	LanguageVersion int      `json:"languageVersion,omitempty"`
	Triggers        []string `json:"triggers,omitempty"`
	Descriptors     []string `json:"descriptors,omitempty"`
	StateVariables  []string `json:"stateVariables,omitempty"`
	StateMaps       []string `json:"stateMaps,omitempty"`
	Textual         struct {
		Triggers       string `json:"triggers,omitempty"`
		Descriptors    string `json:"descriptors,omitempty"`
		StateVariables string `json:"stateVariables,omitempty"`
		StateMaps      string `json:"stateMaps,omitempty"`
	} `json:"textual,omitempty"`
}

type HtContractSend

type HtContractSend struct {
	AddressSend string
	AddressRecv string
	Amount      int64
}

type NetType

type NetType byte

type NewVsysApiReq

type NewVsysApiReq struct {
	NodeAddress string
	Network     NetType
	Name        string // can be get by GetSdkName()
	ApiKey      string
}

type NodeHeath

type NodeHeath struct {
	SelfAddr            string    `json:",omitempty"`
	AllAddrList         []string  `json:",omitempty"`
	SuspendedAddrList   []string  `json:",omitempty"`
	ConnectedAddrList   []string  `json:",omitempty"`
	BlacklistedAddrList []string  `json:",omitempty"`
	LastBlockHeight     int64     `json:",omitempty"`
	LastBlockSignature  string    `json:",omitempty"`
	LastBlockTimestamp  time.Time `json:",omitempty"`
	UnconfirmedSize     int64     // 0 is valid value
	ErrMsg              string    `json:",omitempty"`
}

type NodeListHeathCheckResp

type NodeListHeathCheckResp struct {
	HealthList       []NodeHeath
	SyncRelationList []NodeSyncRelation
	ProblemList      []string
}

func NodeListHeathCheck

func NodeListHeathCheck(nodeAddrList []string, NetType NetType) (resp NodeListHeathCheckResp)

type NodePeerAll

type NodePeerAll struct {
	Address  string `json:"address"`
	LastSeen int64  `json:"lastSeen"`
}

type NodePeerBlacklisted

type NodePeerBlacklisted struct {
	Hostname  string `json:"hostname"`
	Timestamp int64  `json:"timestamp"`
	Reason    string `json:"reason"`
}

type NodePeerConnected

type NodePeerConnected struct {
	Address            string `json:"address"`
	ApplicationName    string `json:"applicationName"`
	ApplicationVersion string `json:"applicationVersion"`
	DeclaredAddress    string `json:"declaredAddress"`
	PeerName           string `json:"peerName"`
	PeerNonce          int64  `json:"peerNonce"`
}

type NodePeerSuspended

type NodePeerSuspended struct {
	Hostname  string `json:"hostname"`
	Timestamp int64  `json:"timestamp"`
}

type NodeSyncRelation

type NodeSyncRelation struct {
	LastNodeAddr  string `json:",omitempty"`
	CheckNodeAddr string `json:",omitempty"`
	FindHeight    int64  `json:",omitempty"`
	ErrMsg        string `json:",omitempty"`
}

type PaymentChannelAbortReq

type PaymentChannelAbortReq struct {
	Sender     *Account
	ContractId string
	ChannelId  string
}

type PaymentChannelCollectReq

type PaymentChannelCollectReq struct {
	Receiver              *Account
	ContractId            string
	ChannelId             string
	Amount                int64
	Payment_signature_str string
}

type PaymentChannelCreateAndLoadReq

type PaymentChannelCreateAndLoadReq struct {
	Sender           *Account
	ContractId       string
	RecipientAddress string
	Amount           int64
	TimeStamp        int64
}

recipient_address = Account(chain=chain, seed='<recipient-seed>', nonce=0) create_recipient_data_entry = DataEntry(recipient_address.address, Type.address) create_amount_data_entry = DataEntry(50, Type.amount) create_expiration_time_data_entry = DataEntry(response2["timestamp"] + 10000000000, Type.timestamp)

create_data_stack = [create_recipient_data_entry, create_amount_data_entry, create_expiration_time_data_entry]

type PaymentChannelExtendExpirationTimeReq

type PaymentChannelExtendExpirationTimeReq struct {
	Sender     *Account
	ContractId string
	ChannelId  string
	TimeStamp  int64
}

type PaymentChannelLoadReq

type PaymentChannelLoadReq struct {
	Sender     *Account
	ContractId string
	ChannelId  string
	Amount     int64
}

type PaymentChannelUnloadReq

type PaymentChannelUnloadReq struct {
	Sender     *Account
	ContractId string
	ChannelId  string
}

type Proof

type Proof struct {
	ProofType string `json:"proofType"`
	PublicKey string `json:"publicKey"`
	Address   string `json:"address"` // from read
	Signature string `json:"signature"`
}

type RegisterContractPaymentChannelReq

type RegisterContractPaymentChannelReq struct {
	Sender        *Account
	Vsys_token_id string
}

type RegisterContractTokenReq

type RegisterContractTokenReq struct {
	Sender              *Account
	Max                 int64
	Unity               int64
	TokenDescription    string
	ContractDescription string
}

type Textual

type Textual struct {
	Triggers       string
	Descriptors    string
	StateVariables string
}

type TokenDepositReq

type TokenDepositReq struct {
	Sender            *Account
	TokenId           string
	ReceiveAddress    string
	TokenContractId   string
	ReceiveContractId string
	Amount            int64
}

type TokenInfoResp

type TokenInfoResp struct {
	TokenID     string `json:"tokenId"`
	ContractID  string `json:"contractId"`
	Max         int64  `json:"max"`
	Total       int64  `json:"total"`
	Unity       int    `json:"unity"`
	Description string `json:"description"`
}

type TokenIssueReq

type TokenIssueReq struct {
	Sender     *Account
	TokenId    string
	ContractId string
	Amount     int64
}

type TokenWithdrawReq

type TokenWithdrawReq struct {
	Sender            *Account
	TokenId           string
	ReceiveAddress    string
	TokenContractId   string
	ReceiveContractId string
	Amount            int64
}

type Transaction

type Transaction struct {
	TxId            string `json:"txId,omitempty"`
	Timestamp       int64  `json:"timestamp"`
	Fee             int64  `json:"fee"`
	FeeScale        int16  `json:"feeScale"`
	Amount          int64  `json:"amount,omitempty"`
	SenderPublicKey string `json:"senderPublicKey"`
	Attachment      []byte `json:"attachment,omitempty"`
	Recipient       string `json:"recipient,omitempty"`
	Signature       string `json:"signature,omitempty"`
	// contract
	Contract      string `json:"contract,omitempty"`
	InitData      string `json:"initData,omitempty"`
	ContractId    string `json:"contractId,omitempty"`
	TokenIdx      int32  `json:"tokenIdx,omitempty"`
	Description   string `json:"description,omitempty"`
	FunctionIndex int16  `json:"functionIndex"`
	FunctionData  string `json:"functionData,omitempty"`
	// contains filtered or unexported fields
}

func NewCancelLeaseTransaction

func NewCancelLeaseTransaction(txId string) *Transaction

func NewExecuteTransaction

func NewExecuteTransaction(contractId string, funcIdx int16, funcData string, attachment []byte) *Transaction

func NewLeaseTransaction

func NewLeaseTransaction(recipient string, amount int64) *Transaction

func NewPaymentTransaction

func NewPaymentTransaction(recipient string, amount int64, attachment []byte) *Transaction

func NewRegisterTransaction

func NewRegisterTransaction(contract string, data string, contractDescription string) *Transaction

func (*Transaction) BuildTxData

func (tx *Transaction) BuildTxData() []byte

BuildTxData generate data which is used to be signed

func (*Transaction) GetTxType

func (tx *Transaction) GetTxType() int

type TransactionList2Req

type TransactionList2Req struct {
	Address string
	Limit   int
	Offset  int
	TxType  int
}

type TransactionResponse

type TransactionResponse struct {
	HistoryTransaction
	CommonResp
}

type VsysApi

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

func NewPublicMainNetApi

func NewPublicMainNetApi() *VsysApi

func NewPublicTestNetApi

func NewPublicTestNetApi() *VsysApi

func NewVsysApi

func NewVsysApi(req NewVsysApiReq) *VsysApi

func (*VsysApi) AddToWallet

func (sdk *VsysApi) AddToWallet(account *Account)

func (*VsysApi) DeleteAccountFromWallet

func (sdk *VsysApi) DeleteAccountFromWallet(addr string)

func (*VsysApi) GetAccountAllHistoryTransactionCallback

func (sdk *VsysApi) GetAccountAllHistoryTransactionCallback(address string, TxType int, visitor func(tran HistoryTransaction)) (err error)

TxType 0 to return all transaction

func (*VsysApi) GetAccountBalance

func (sdk *VsysApi) GetAccountBalance(address string) (v int64, err error)

func (*VsysApi) GetAccountFromWallet

func (sdk *VsysApi) GetAccountFromWallet(addr string) *Account

func (*VsysApi) GetAccountHistoryTransactionList

func (sdk *VsysApi) GetAccountHistoryTransactionList(address string, limit int) (list []HistoryTransaction, err error)

func (*VsysApi) GetAccountHistoryTransactionList2

func (sdk *VsysApi) GetAccountHistoryTransactionList2(req TransactionList2Req) (list []HistoryTransaction, err error)

func (*VsysApi) GetBlockHeight

func (sdk *VsysApi) GetBlockHeight() (h int, errMsg string)

func (*VsysApi) GetHistoryTransactionById

func (sdk *VsysApi) GetHistoryTransactionById(txId string) (ht HistoryTransaction, err error)

func (*VsysApi) GetNodeHeath

func (api *VsysApi) GetNodeHeath() NodeHeath

func (*VsysApi) GetSdkName

func (sdk *VsysApi) GetSdkName() string

func (*VsysApi) GetUnconfirmedHistoryTransactionList

func (sdk *VsysApi) GetUnconfirmedHistoryTransactionList() (list []HistoryTransaction, err error)

func (*VsysApi) IsValidAddress

func (sdk *VsysApi) IsValidAddress(address string) bool

func (*VsysApi) MustApiCallBlockSeq

func (sdk *VsysApi) MustApiCallBlockSeq(from int, to int) (output []Block)

func (*VsysApi) MustApiCallExecuteContract

func (api *VsysApi) MustApiCallExecuteContract(req ApiCallExecuteContractReq) (resp TransactionResponse)

func (*VsysApi) MustApiCallGetContractData

func (api *VsysApi) MustApiCallGetContractData(contractId string, key string) (resp GetContractDataResp)

func (*VsysApi) MustApiCallRegisterContract

func (api *VsysApi) MustApiCallRegisterContract(req ApiCallRegisterContractReq) (resp TransactionResponse)

func (*VsysApi) MustApiGetBlockHeightBySignature

func (sdk *VsysApi) MustApiGetBlockHeightBySignature(signature string) int64

func (*VsysApi) MustApiGetBlockLast

func (sdk *VsysApi) MustApiGetBlockLast() Block

func (*VsysApi) MustApiGetNodeStatus

func (sdk *VsysApi) MustApiGetNodeStatus() (resp ApiRespNodeStatus)

func (*VsysApi) MustApiGetPeersAll

func (sdk *VsysApi) MustApiGetPeersAll() []NodePeerAll

func (*VsysApi) MustApiGetPeersBlacklisted

func (sdk *VsysApi) MustApiGetPeersBlacklisted() []NodePeerBlacklisted

func (*VsysApi) MustApiGetPeersConnected

func (sdk *VsysApi) MustApiGetPeersConnected() []NodePeerConnected

func (*VsysApi) MustApiGetPeersSuspended

func (sdk *VsysApi) MustApiGetPeersSuspended() []NodePeerSuspended

func (*VsysApi) MustContractLock

func (api *VsysApi) MustContractLock(req ContractLockReq) (resp TransactionResponse)

func (*VsysApi) MustGetAccountBalance

func (sdk *VsysApi) MustGetAccountBalance(address string) (v int64)

func (*VsysApi) MustGetAccountBalanceString

func (sdk *VsysApi) MustGetAccountBalanceString(address string) (s string)

func (*VsysApi) MustGetAccountHistoryTransactionList

func (sdk *VsysApi) MustGetAccountHistoryTransactionList(address string, limit int) (list []HistoryTransaction)

func (*VsysApi) MustGetBlockCallbackDesc

func (sdk *VsysApi) MustGetBlockCallbackDesc(cb func(block Block) bool)

func (*VsysApi) MustGetBlockHeight

func (sdk *VsysApi) MustGetBlockHeight() int

func (*VsysApi) MustGetContractTokenBalance

func (sdk *VsysApi) MustGetContractTokenBalance(address string, tokenId string) (v int64)

func (*VsysApi) MustGetContractTokenBalanceObj

func (sdk *VsysApi) MustGetContractTokenBalanceObj(address string, tokenId string) GetContractTokenBalanceResp
{
  "address" : "AR695aEbZPsDQzVjHBLvDYxadrpe21zdfHf",
  "tokenId" : "TWZZfKFqcaNVe5TrphLRNEm5DQFnBRJMjDDByqv84",
  "balance" : 35141117913,
  "unity" : 1000000000
}

func (*VsysApi) MustGetHistoryTransactionById

func (sdk *VsysApi) MustGetHistoryTransactionById(txId string) (ht HistoryTransaction)

func (*VsysApi) MustGetNodeVersion

func (sdk *VsysApi) MustGetNodeVersion() (version string)

func (*VsysApi) MustGetTokenInfo

func (sdk *VsysApi) MustGetTokenInfo(tokenId string) TokenInfoResp
{
  "tokenId" : "TWZZfKFqcaNVe5TrphLRNEm5DQFnBRJMjDDByqv84",
  "contractId" : "CC8Jx8aLkKVQmzuHBWNnhCSkn1GBLcjZ32k",
  "max" : 1500000000000000000,
  "total" : 1000000000000000000,
  "unity" : 1000000000,
  "description" : "15sb7d"
}

func (*VsysApi) MustGetTransactionUnconfirmedSize

func (sdk *VsysApi) MustGetTransactionUnconfirmedSize() int64

func (*VsysApi) MustPaymentChannelAbort

func (api *VsysApi) MustPaymentChannelAbort(req PaymentChannelAbortReq) (resp TransactionResponse)

func (*VsysApi) MustPaymentChannelCollect

func (api *VsysApi) MustPaymentChannelCollect(req PaymentChannelCollectReq) (resp TransactionResponse)

func (*VsysApi) MustPaymentChannelCreateAndLoad

func (api *VsysApi) MustPaymentChannelCreateAndLoad(req PaymentChannelCreateAndLoadReq) (resp TransactionResponse)

func (*VsysApi) MustPaymentChannelExtendExpirationTime

func (api *VsysApi) MustPaymentChannelExtendExpirationTime(req PaymentChannelExtendExpirationTimeReq) (resp TransactionResponse)

func (*VsysApi) MustPaymentChannelGetChannelCapacity

func (api *VsysApi) MustPaymentChannelGetChannelCapacity(ContractId string, ChannelId string) int64

func (*VsysApi) MustPaymentChannelGetChannelCollectedBalance

func (api *VsysApi) MustPaymentChannelGetChannelCollectedBalance(ContractId string, ChannelId string) int64

func (*VsysApi) MustPaymentChannelGetChannelExpirationTime

func (api *VsysApi) MustPaymentChannelGetChannelExpirationTime(ContractId string, ChannelId string) int64

func (*VsysApi) MustPaymentChannelGetChannelIsOpen

func (api *VsysApi) MustPaymentChannelGetChannelIsOpen(ContractId string, ChannelId string) bool

true mean channel is open, false mean sender abort it. false can not call ExtendExpirationTime on it.

func (*VsysApi) MustPaymentChannelGetCreatorAddressOfChannel

func (api *VsysApi) MustPaymentChannelGetCreatorAddressOfChannel(ContractId string, ChannelId string) string

func (*VsysApi) MustPaymentChannelGetCreatorPublicKeyOfChannel

func (api *VsysApi) MustPaymentChannelGetCreatorPublicKeyOfChannel(ContractId string, ChannelId string) string

func (*VsysApi) MustPaymentChannelGetMasterContractBalance

func (api *VsysApi) MustPaymentChannelGetMasterContractBalance(ContractId string, address string) int64

func (*VsysApi) MustPaymentChannelGetRecipientAddressOfChannel

func (api *VsysApi) MustPaymentChannelGetRecipientAddressOfChannel(ContractId string, ChannelId string) string

func (*VsysApi) MustPaymentChannelLoad

func (api *VsysApi) MustPaymentChannelLoad(req PaymentChannelLoadReq) (resp TransactionResponse)

func (*VsysApi) MustPaymentChannelUnload

func (api *VsysApi) MustPaymentChannelUnload(req PaymentChannelUnloadReq) (resp TransactionResponse)

func (*VsysApi) MustRegisterContractLock

func (api *VsysApi) MustRegisterContractLock(Sender *Account, Vsys_token_id string) (resp TransactionResponse)

func (*VsysApi) MustRegisterContractPaymentChannel

func (api *VsysApi) MustRegisterContractPaymentChannel(req RegisterContractPaymentChannelReq) (resp TransactionResponse)

func (*VsysApi) MustRegisterContractToken

func (api *VsysApi) MustRegisterContractToken(req RegisterContractTokenReq) (resp TransactionResponse)

func (*VsysApi) MustSendPaymentSimpleAsync2

func (sdk *VsysApi) MustSendPaymentSimpleAsync2(senderAccount *Account, receiverAddress string, amount int64) (resp TransactionResponse)

func (*VsysApi) MustSendPaymentSimpleSync

func (sdk *VsysApi) MustSendPaymentSimpleSync(senderAccount *Account, receiverAddress string, amount int64)

func (*VsysApi) MustSendTokenSimpleSync

func (sdk *VsysApi) MustSendTokenSimpleSync(tokenId string, senderAccount *Account, receiverAddress string, amount int64) (resp TransactionResponse)

func (*VsysApi) MustTokenDeposit

func (api *VsysApi) MustTokenDeposit(req TokenDepositReq) (resp TransactionResponse)

func (*VsysApi) MustTokenIssue

func (api *VsysApi) MustTokenIssue(req TokenIssueReq) (resp TransactionResponse)

func (*VsysApi) MustTokenWithdraw

func (api *VsysApi) MustTokenWithdraw(req TokenWithdrawReq) (resp TransactionResponse)

func (*VsysApi) MustWaitPaymentConfirmedByTranId

func (sdk *VsysApi) MustWaitPaymentConfirmedByTranId(id string, deadline time.Time)

func (*VsysApi) MustWaitPaymentOkByTransactionResponse

func (api *VsysApi) MustWaitPaymentOkByTransactionResponse(resp TransactionResponse)

func (*VsysApi) NewAccountFromSeedAndNonce

func (sdk *VsysApi) NewAccountFromSeedAndNonce(seed string, nonce int) (acc *Account)

func (*VsysApi) NewAccountFromSeedAndNonceV2

func (sdk *VsysApi) NewAccountFromSeedAndNonceV2(seed string, nonce int) (acc *Account)

func (*VsysApi) NewAccountFromSeedHash

func (sdk *VsysApi) NewAccountFromSeedHash(seedHash []byte) (acc *Account)

func (*VsysApi) SendCancelLeasingTx

func (api *VsysApi) SendCancelLeasingTx(tx *Transaction) (resp TransactionResponse, err error)

func (*VsysApi) SendExecuteContractTx

func (api *VsysApi) SendExecuteContractTx(tx *Transaction) (resp TransactionResponse, err error)

func (*VsysApi) SendLeasingTx

func (api *VsysApi) SendLeasingTx(tx *Transaction) (resp TransactionResponse, err error)

func (*VsysApi) SendPaymentSimpleAsync

func (sdk *VsysApi) SendPaymentSimpleAsync(senderAccount *Account, receiverAddress string, amount int64) (err error)

transfer vsys, do not wait the transaction go to chain

func (*VsysApi) SendPaymentSimpleAsync2

func (sdk *VsysApi) SendPaymentSimpleAsync2(senderAccount *Account, receiverAddress string, amount int64) (resp TransactionResponse, err error)

func (*VsysApi) SendPaymentSimpleSync

func (sdk *VsysApi) SendPaymentSimpleSync(senderAccount *Account, receiverAddress string, amount int64) (err error)

transfer vsys, wait the transaction go to chain,(it may be refused by the chain)

func (*VsysApi) SendPaymentTx

func (api *VsysApi) SendPaymentTx(tx *Transaction) (resp TransactionResponse, err error)

func (*VsysApi) SendRegisterContractTx

func (api *VsysApi) SendRegisterContractTx(tx *Transaction) (resp TransactionResponse, err error)

func (*VsysApi) SendTokenSimpleAsync

func (sdk *VsysApi) SendTokenSimpleAsync(tokenId string, senderAccount *Account, receiverAddress string, amount int64) (err error)

func (*VsysApi) SendTokenSimpleAsync2

func (sdk *VsysApi) SendTokenSimpleAsync2(tokenId string, senderAccount *Account, receiverAddress string, amount int64) (resp TransactionResponse, err error)

func (*VsysApi) WaitPaymentConfirmedByTranId

func (sdk *VsysApi) WaitPaymentConfirmedByTranId(id string, deadline time.Time) (err error)

type VsysApiList

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

func (*VsysApiList) AddVsysApi

func (list *VsysApiList) AddVsysApi(api *VsysApi)

func (*VsysApiList) GetByName

func (list *VsysApiList) GetByName(name string) *VsysApi

func (*VsysApiList) GetList

func (list *VsysApiList) GetList() []*VsysApi

Jump to

Keyboard shortcuts

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