vsys

package
v0.0.0-...-95c96ca Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiNodeVersion      = "/node/version"
	ApiBroadcastPayment = "/vsys/broadcast/payment"
	ApiBlockHeight      = "/blocks/height"
	ApiGetBlockAt       = "/blocks/at/%d"
	ApiGetBlockBySig    = "/blocks/signature/%s"
	ApiBlocks           = "/blocks/seq/%d/%d"

	// leasing
	ApiBroadcastLease       = "/leasing/broadcast/lease"
	ApiBroadcastCancelLease = "/leasing/broadcast/cancel"

	// transactions
	ApiUnConfirmedTransaction  = "/transactions/unconfirmed"
	ApiGetTransactionInfo      = "/transactions/info/%s"
	ApiGetTransactionByAddress = "/transactions/address/%s/limit/%d"
	ApiGetTransactionList      = "/transactions/list"

	// peers
	ApiGetPeersConnected = "/peers/connected"

	// consensus
	ApiGetAllSlotsInfo  = "/consensus/allSlotsInfo"
	ApiGetConsensusAlgo = "/consensus/algo"

	// address
	ApiGetAddressDetail  = "/addresses/balance/details/%s"
	ApiGetAddressValid   = "/addresses/validate/%s"
	ApiGetAddressBalance = "/addresses/balance/%s"

	//contract
	ApiContractBroadcastRegister = "/contract/broadcast/register"
	ApiContractBroadcastExecute  = "/contract/broadcast/execute"
	ApiContractInfo              = "/contract/info/%s"
	ApiTokenInfo                 = "/contract/tokenInfo/%s"
	ApiContractTokenBalance      = "/contract/balance/%s/%s" // /contract/balance/{address}/{tokenId}
)
View Source
const (
	Protocol = "v.systems"
	Api      = 3

	// 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

	TokenContract               = "" /* 1186-byte string literal not displayed */
	TokenContractWithSplit      = "" /* 1272-byte string literal not displayed */
	ContractDescriptor          = "" /* 570-byte string literal not displayed */
	ContractWithSplitDescriptor = "" /* 615-byte string literal not displayed */
)
View Source
const (
	DeTypePublicKey       = 0x01
	DeTypeAddress         = 0x02
	DeTypeAmount          = 0x03
	DeTypeInt32           = 0x04
	DeTypeShortText       = 0x05
	DeTypeContractAccount = 0x06
	DETypeAccount         = 0x07
)

Variables

View Source
var D = gf([]int64{0x78a3, 0x1359, 0x4dca, 0x75eb,
	0xd8ab, 0x4141, 0x0a4d, 0x0070,
	0xe898, 0x7779, 0x4079, 0x8cc7,
	0xfe73, 0x2b6f, 0x6cee, 0x5203})
View Source
var D2 = gf([]int64{0xf159, 0x26b2, 0x9b94, 0xebd6,
	0xb156, 0x8283, 0x149a, 0x00e0,
	0xd130, 0xeef3, 0x80f2, 0x198e,
	0xfce7, 0x56df, 0xd9dc, 0x2406})
View Source
var I = gf([]int64{0xa0b0, 0x4a0e, 0x1b27, 0xc4ee,
	0xe478, 0xad2f, 0x1806, 0x2f43,
	0xd7a7, 0x3dfb, 0x0099, 0x2b4d,
	0xdf0b, 0x4fc1, 0x2480, 0x2b83})
View Source
var K = []int64{}/* 160 elements not displayed */

Constantes de cada ronda del SHA-512

View Source
var L = []int64{0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
	0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10}
View Source
var X = gf([]int64{0xd51a, 0x8f25, 0x2d60, 0xc956,
	0xa7b2, 0x9525, 0xc760, 0x692c,
	0xdc5c, 0xfdd6, 0xe231, 0xc0a4,
	0x53fe, 0xcd6e, 0x36d3, 0x2169})
View Source
var Y = gf([]int64{0x6658, 0x6666, 0x6666, 0x6666,
	0x6666, 0x6666, 0x6666, 0x6666,
	0x6666, 0x6666, 0x6666, 0x6666,
	0x6666, 0x6666, 0x6666, 0x6666})

Functions

func A

func A(o []int64, a []int64, b []int64)

func AesDecrypt

func AesDecrypt(key []byte, data []byte) (origData []byte, err error)

AesDecrypt aes cbc PKCS5Padding

func AesEncrypt

func AesEncrypt(key []byte, data []byte) ([]byte, error)

AesEncrypt is aes encrypt function key can be any length data can be any length iv is random,multi encrypt will get different result PKCS5Padding , CBC pattern

func Base58Decode

func Base58Decode(b string) []byte

Decode decodes a modified base58 string to a byte slice.

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 GenerateSeed

func GenerateSeed() string

GenerateSeed generates seed string

func HashChain

func HashChain(nonceSecret []byte) []byte

func InitApi

func InitApi(nodeAddress string, network NetType)

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 M

func M(o []int64, a []int64, b []int64)

optimized by Miguel

func Post

func Post(url string, data interface{}) (body []byte, err error)

func PostWithTimeOut

func PostWithTimeOut(url string, data interface{}, duration time.Duration) (body []byte, err error)

func PublicKeyToAddress

func PublicKeyToAddress(publicKey string, network NetType) string

PublicKeyToAddress return address with base58 encoded

func S

func S(o []int64, a []int64)

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 UrlGetContent

func UrlGetContent(url string) (body []byte, err error)

func Verify

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

func Z

func Z(o []int64, a []int64, b []int64)

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) Address

func (acc *Account) Address() string

get account address 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 string) *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 string) *Transaction

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

func (*Account) BuildRegisterContract

func (acc *Account) BuildRegisterContract(contract string, max int64, unity int64, tokenDescription string, contractDescription string) *Transaction

BuildRegisterContract build RegisterContract transaction

func (*Account) BuildSendTokenTransaction

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

BuildExecuteContract build SendToken transaction

func (*Account) GetInfo

func (acc *Account) GetInfo() (AccountInfo, error)

Get account V Coin balance

func (*Account) GetTokenBalance

func (acc *Account) GetTokenBalance(tokenId string) (TokenBalance, error)

func (*Account) GetTransferHistory

func (acc *Account) GetTransferHistory(limit int64, offset int64, txType int64) (TxHistoryList, error)

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) 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 AccountInfo

type AccountInfo struct {
	Address        string
	Regular        int64
	MintingAverage int64
	Available      int64
	Effective      int64
	Height         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 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

type DataEntry

type DataEntry struct {
	Type  int8
	Value interface{}
}

type Func

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

type NetType

type NetType byte

type Proof

type Proof struct {
	ProofType string `json:"proofType"`
	PublicKey string `json:"publicKey"`
	Signature string `json:"signature"`
}

type Textual

type Textual struct {
	Triggers       string
	Descriptors    string
	StateVariables string
}

type TokenBalance

type TokenBalance struct {
	Error   int    `json:"error"`
	Message string `json:"message"`
	Address string `json:"address"`
	TokenId string `json:"tokenId"`
	Balance int64  `json:"balance"`
	Unity   int64  `json:"unity"`
}

type TokenInfo

type TokenInfo struct {
	TokenId     string `json:"tokenId"`
	ContractId  string `json:"contractId"`
	Max         int64  `json:"max"`
	Total       int64  `json:"total"`
	Unity       int64  `json:"unity"`
	Description string `json:"description"`
}

func GetTokenInfo

func GetTokenInfo(tokenId string) (TokenInfo, error)

Get token info by token_id

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      string `json:"attachment,omitempty"`
	Recipient       string `json:"recipient,omitempty"`
	Signature       string `json:"signature"`
	// 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,omitempty"`
	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 string) *Transaction

func NewLeaseTransaction

func NewLeaseTransaction(recipient string, amount int64) *Transaction

func NewPaymentTransaction

func NewPaymentTransaction(recipient string, amount int64, attachment string) *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) TxType

func (tx *Transaction) TxType() int

type TransactionResponse

type TransactionResponse struct {
	Type       uint8   `json:"type"`
	Id         string  `json:"id"`
	Fee        int64   `json:"fee"`
	Timestamp  int64   `json:"timestamp"`
	Proofs     []Proof `json:"proofs"`
	Recipient  string  `json:"recipient"`
	FeeScale   int16   `json:"feeScale"`
	Amount     int64   `json:"amount"`
	Attachment string  `json:"attachment"`
	CommonResp
}

func SendCancelLeasingTx

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

func SendExecuteContractTx

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

func SendLeasingTx

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

func SendPaymentTx

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

func SendRegisterContractTx

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

type TxHistoryList

type TxHistoryList struct {
	Error        int    `json:"error"`
	Message      string `json:"message"`
	TotalCount   int64  `json:"totalCount"`
	Size         int    `json:"size"`
	Transactions []struct {
		Type      int64
		Id        string
		Fee       int64
		FeeScale  int64 `json:"feeScale"`
		Timestamp int64 `json:"timestamp"`
		Proofs    []struct {
			ProofType string `json:"proofType"`
			PublicKey string `json:"publicKey"`
			Address   string `json:"address"`
			Signature string `json:"signature"`
		}
		Recipient  string `json:"recipient"`
		Amount     int64  `json:"amount"`
		Attachment string `json:"attachment"`
		Status     string `json:"status"`
		FeeCharged int64  `json:"feeCharged"`
		Height     int64  `json:"height"`
	} `json:"transactions"`
}

func GetTransactionList

func GetTransactionList(address string, limit int64, offset int64, txType int64) (TxHistoryList, error)

txType eg: TxTypePayment | TxTypeLeasing txType <= 0 will return all kind of transactions

type VsysApi

type VsysApi struct {
	NodeAddress string
	Network     NetType
}

func GetVsysApi

func GetVsysApi() *VsysApi

func (*VsysApi) Get

func (a *VsysApi) Get(path string) ([]byte, error)

func (*VsysApi) Post

func (a *VsysApi) Post(path string, data interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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