nuls

package module
v0.0.0-...-b74a134 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 8 Imported by: 0

README

nuls-go

Documentation

Overview

Package nuls is Go bindings to the cryptocurrency nuls API

  • Copyright (c) 2019. Dabank Authors
  • All rights reserved.

Index

Constants

View Source
const (
	// coinbase 交易
	TxTypeCoinbase = iota + 1
	// 转账交易
	TxTypeTransfer
	// 设置别名
	TxTypeAlias
	// 创建共识节点交易
	TxTypeRegisterAgent
	// 委托交易(加入共识)
	TxTypeJoinConsensus
	// 取消委托交易(退出共识)
	TxTypeCancelDeposit
	// 黄牌惩罚
	TxTypeYellowPunish
	// 红牌惩罚
	TxTypeRedPunish
	// 停止节点(删除共识节点)
	TxTypeStopAgent
	// 跨链转账交易
	TxTypeCrossChainTransfer
	// 注册链交易
	TxTypeRegisterChainAndAsset
	// 销毁链
	TxTypeDestroyChainAndAsset
	// 为链新增一种资产
	TxTypeAddAssetToChain
	// 删除链上资产
	TxTypeRemoveAssetFromChain
)
View Source
const (
	// 创建智能合约交易
	TxTypeCreateContract = iota + 100
	// 调用智能合约交易
	TxTypeCallContract
	// 删除智能合约交易
	TxTypeDeleteContract
)

Variables

This section is empty.

Functions

func AmountToFloat64

func AmountToFloat64(xmr int64) float64

AmountToFloat64 converts raw atomic NULS to a float64

func AmountToInt64

func AmountToInt64(xmr float64) int64

AmountToInt64 converts a raw atomic NULS balance to a more human readable format.

Types

type AccountInfo

type AccountInfo struct {
	Success bool `json:"success"`
	Data    struct {
		PageNumber int `json:"pageNumber"`
		PageSize   int `json:"pageSize"`
		Total      int `json:"total"`
		Pages      int `json:"pages"`
		List       []struct {
			Address string `json:"address"`
			Alias   string `json:"alias"`
			PubKey  string `json:"pubKey"`
			// Extend     interface{} `json:"extend"`
			CreateTime int64  `json:"createTime"`
			Encrypted  bool   `json:"encrypted"`
			Remark     string `json:"remark"`
			Ok         bool   `json:"ok"`
		} `json:"list"`
	} `json:"data"`
}

type AccountList

type AccountList struct {
	Success bool `json:"success"`
	Data    struct {
		List []string `json:"list"`
	} `json:"data"`
}

type Balance

type Balance struct {
	Success bool `json:"success"`
	Data    struct {
		Balance struct {
			Value int64 `json:"value"`
		} `json:"balance"`
		Locked struct {
			Value int `json:"value"`
		} `json:"locked"`
		Usable struct {
			Value int64 `json:"value"`
		} `json:"usable"`
	} `json:"data"`
}

type BlockHeight

type BlockHeight struct {
	Success bool `json:"success"`
	Data    struct {
		Value int `json:"value"`
	} `json:"data"`
}

type BlockInfo

type BlockInfo struct {
	Success bool `json:"success"`
	Data    struct {
		List []struct {
			Hash                 string        `json:"hash"`
			PreHash              string        `json:"preHash"`
			MerkleHash           string        `json:"merkleHash"`
			StateRoot            string        `json:"stateRoot"`
			Time                 int64         `json:"time"`
			Height               int           `json:"height"`
			TxCount              int           `json:"txCount"`
			PackingAddress       string        `json:"packingAddress"`
			Extend               string        `json:"extend"`
			RoundIndex           int           `json:"roundIndex"`
			ConsensusMemberCount int           `json:"consensusMemberCount"`
			RoundStartTime       int64         `json:"roundStartTime"`
			PackingIndexOfRound  int           `json:"packingIndexOfRound"`
			Reward               int           `json:"reward"`
			Fee                  int           `json:"fee"`
			ConfirmCount         int           `json:"confirmCount"`
			Size                 int           `json:"size"`
			TxList               []transaction `json:"txList"`
			ScriptSig            string        `json:"scriptSig"`
		} `json:"list"`
	} `json:"data"`
}

type Client

type Client struct {

	// Verbose when true, talks a lot
	Verbose bool

	// BeforeRequest fires before every request,
	// can be used in rate limit.
	// request is aborted if there is an error
	BeforeRequest func(requestType string, option string, outcome interface{}) error
	// contains filtered or unexported fields
}

Client nuls API client Clients are safe for concurrent use by multiple goroutines.

func New

func New(baseURL string) *Client

New initializes a new nuls API client

func (*Client) AddressBalance

func (c *Client) AddressBalance(address string) (info Balance, err error)

/api/accountledger/balance/{address} 账户地址查询账户余额

func (*Client) Block

func (c *Client) Block(startHeight, size int) (info BlockInfo, err error)

根据区块高度查询区块列表,包含区块打包的所有交易信息

func (*Client) BlockHeight

func (c *Client) BlockHeight() (info BlockHeight, err error)

"/api/block/newest/height" 查询最新区块高度

func (*Client) ContractTransfer

func (c *Client) ContractTransfer(address, toAddress, password string, gasLimit, price int, amount int64) (info Transfer, err error)

/api/contract/transfer 向智能合约地址转账

func (*Client) CreateAccount

func (c *Client) CreateAccount(count int, password string) (info AccountList, err error)

创建账户

func (*Client) GetAccount

func (c *Client) GetAccount(account string) (info AccountInfo, err error)

GetAccount Get account information given an account ID.

func (*Client) GetTransaction

func (c *Client) GetTransaction(txId string) (info Transaction, err error)

/api/tx/hash/{hash} 根据hash查询交易

func (*Client) MultipleAddressTransfer

func (c *Client) MultipleAddressTransfer(inputs []Input, outPuts []OutPut) (info Transfer, err error)

/api/accountledger/multipleAddressTransfer 多地址转账

func (*Client) Transfer

func (c *Client) Transfer(address, toAddress, password string, amount int64) (info Transfer, err error)

/api/accountledger/transfer 转账

func (*Client) ValidateAddress

func (c *Client) ValidateAddress(address string) (info ValidateAddress, err error)

api/account/validate/{address} [验证地址格式是否正确]

func (*Client) ValidateContractAddress

func (c *Client) ValidateContractAddress(address string) (info ValidateContract, err error)

/api/contract/{address} 验证是否为合约地址

func (*Client) WalletBalance

func (c *Client) WalletBalance() (info Balance, err error)

[余额] 查询本地所有账户总余额

type ErrorResponse

type ErrorResponse struct {
	Success bool `json:"success"`
	Data    struct {
		Code string `json:"code"`
		Msg  string `json:"msg"`
	} `json:"data"`
}

Response shows up when there is something wrong.

type Input

type Input struct {
	Address  string `json:"address"`
	Password string `json:"password"`
}

type M

type M map[string]interface{}

M is a type shorthand for param input

type OutPut

type OutPut struct {
	ToAddress string `json:"toAddress"`
	Amount    int64  `json:"amount"`
}

type Transaction

type Transaction struct {
	Success bool        `json:"success"`
	Data    transaction `json:"data"`
}

type Transfer

type Transfer struct {
	Success bool `json:"success"`
	Data    struct {
		Value string `json:"value"`
	} `json:"data"`
}

type ValidateAddress

type ValidateAddress struct {
	Success bool `json:"success"`
	Data    struct {
		Value bool `json:"value"`
	} `json:"data"`
}

type ValidateContract

type ValidateContract struct {
	Success bool `json:"success"`
	Data    struct {
		IsContractAddress bool `json:"isContractAddress"`
		IsPayable         bool `json:"isPayable"`
		IsNrc20           bool `json:"isNrc20"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

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