Categorygithub.com/tachyon-protocol/goVsysSdk
modulepackage
0.1.0
Repository: https://github.com/tachyon-protocol/govsyssdk.git
Documentation: pkg.go.dev

# 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

# Functions

No description provided by the author
Encode encodes a byte slice to a modified base58 string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GenerateKeyPair generate Account using seed byte array.
No description provided by the author
InitAccount return account with network initiated.
"Transaction is not in blockchain".
IsValidateAddress checks if address valid.
IsValidatePhrase checks if phrase valid.
Keccak256 calculates and returns the Keccak256 hash of the input data.
Decode decodes a modified base58 string to a byte slice.
MustGenerateSeed generates seed string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PublicKeyToAddress return address with base58 encoded.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
contract funcIdx variable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeTypeAccount = 0x07 // Account is not a data entry, please use DeTypeAddress or DeTypeContractAccount.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
function index.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Network.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TX_TYPE.
No description provided by the author
Fee.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
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] */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author