tron

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: GPL-3.0 Imports: 34 Imported by: 2

README

Filename Declare

manager_xxRef.go Generated xx by hand-operated manager_xx.go Call walletnode to genrate xx

Key tech be used

google protocol buffer: like Json to pack/unpack an instance to be an string (almost also is Hex)

Documentation

Index

Constants

View Source
const (

	//RPCServerCore RPC服务,核心钱包
	RPCServerCore = 0
	//RPCServerExplorer RPC服务,insight-API
	RPCServerExplorer = 1
)
View Source
const (
	// Symbol 币种
	Symbol = "TRX"
	//MasterKey key for master
	MasterKey = "Troncoin seed"
	//CurveType to generate ChildKey by BIP32
	CurveType       = owcrypt.ECC_CURVE_SECP256K1
	Decimals        = 6
	SUN       int64 = 1             //最小单位
	TRX       int64 = SUN * 1000000 //1 TRX = 1000000 * sun
	GasPrice        = SUN * 10
)
View Source
const (
	TRC10 = "trc10"
	TRC20 = "trc20"

	FeeLimit = 10000000
)
View Source
const (
	TRC20_BALANCE_OF_METHOD  = "balanceOf(address)"
	TRC20_TRANSFER_METHOD_ID = "a9059cbb"
	TRX_TRANSFER_EVENT_ID    = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
)
View Source
const (
	SOLIDITY_TYPE_ADDRESS = "address"
	SOLIDITY_TYPE_UINT256 = "uint256"
	SOLIDITY_TYPE_UINT160 = "uint160"
)
View Source
const (
	TransferContract      = "TransferContract"
	TransferAssetContract = "TransferAssetContract"
	TriggerSmartContract  = "TriggerSmartContract"
)

交易单类型

View Source
const (
	SUCCESS = "SUCCESS"
)

状态

Variables

This section is empty.

Functions

func CheckRawTransaction

func CheckRawTransaction(rawTx *openwallet.RawTransaction) error

func DecodeAddress

func DecodeAddress(addr string, isTestnet bool) (string, []byte, error)

func EncodeAddress

func EncodeAddress(hexStr string, isTestnet bool) (string, error)

func InsertSignatureIntoRawTransaction

func InsertSignatureIntoRawTransaction(txHex string, signature string) (string, error)

func ParseTransferEvent

func ParseTransferEvent(data string) (string, int64, error)

Types

type Account

type Account struct {
	AddressHex          string
	Balance             int64
	FreeNetUsage        int64
	AssetV2             map[string]int64
	FreeAssetNetUsageV2 map[string]int64
}

func NewAccount

func NewAccount(json *gjson.Result) *Account

type AccountNet

type AccountNet struct {
	FreeNetUsed    int64
	FreeNetLimit   int64
	NetUsed        int64
	NetLimit       int64
	AssetNetUsed   map[string]int64
	AssetNetLimit  map[string]int64
	TotalNetLimit  int64
	TotalNetWeight int64
}

func NewAccountNet

func NewAccountNet(json *gjson.Result) *AccountNet

type AccountResource added in v1.1.0

type AccountResource struct {
	FreeNetUsed  int64
	FreeNetLimit int64
	NetUsed      int64
	NetLimit     int64
	EnergyUsed   int64
	EnergyLimit  int64
	StorageUsed  int64
	StorageLimit int64
}

func NewAccountResource added in v1.1.0

func NewAccountResource(json *gjson.Result) *AccountResource

type AddrBalance

type AddrBalance struct {
	Address      string
	TronBalance  *big.Int
	TokenBalance *big.Int
	Index        int
}

type AddressDecoderStruct

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

AddressDecoderStruct for Interface AddressDecoder

func NewAddressDecoder

func NewAddressDecoder(wm *WalletManager) *AddressDecoderStruct

NewAddressDecoder 地址解析器

func (*AddressDecoderStruct) PrivateKeyToWIF

func (decoder *AddressDecoderStruct) PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)

PrivateKeyToWIF 私钥转WIF

func (*AddressDecoderStruct) PublicKeyToAddress

func (decoder *AddressDecoderStruct) PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)

PublicKeyToAddress 公钥转地址

func (*AddressDecoderStruct) RedeemScriptToAddress

func (decoder *AddressDecoderStruct) RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)

RedeemScriptToAddress 多重签名赎回脚本转地址

func (*AddressDecoderStruct) WIFToPrivateKey

func (decoder *AddressDecoderStruct) WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)

WIFToPrivateKey WIF转私钥

type Block

type Block struct {
	/*
		 {
			 "blockID":"000000000035e1c0f60afaa8387fd17fd9b84fe4381265ff084d739f814558ea",
			 "block_header":{
				 "raw_data":{"number":3531200,
						 "txTrieRoot":"9d98f6cbbde8302774ab87c003831333e132c89e00009cb1f7da35e1e59ae8ca",
						 "witness_address":"41d1dbde8b8f71b48655bec4f6bb532a0142b88bc0",
						 "parentHash":"000000000035e1bfb3b6f244e5316ce408aa8cea4c348eabe2545247f5a4600c",
						 "version":3,
						 "timestamp":1540545240000},
				 "witness_signature":"6ceedcacd8d0111b48eb4131484de3d13f27a2f4bd8156279d03d4208690158e20a641b77d900e026ee33adc328f9ec674f6483ea7b1ca5a27fa24d7fb23964100"
			 },
			 "transactions":[
				 {"ret":[{"contractRet":"SUCCESS"}],
				  "signature":["40aa520f01cebf12948615b9c5a5df5fe7d57e1a7f662d53907b4aa14f647a3a47be2a097fdb58159d0bee7eb1ff0a15ac738f24643fe5114cab8ec0d52cc04d01"],
				  "txID":"ac005b0a195a130914821a6c28db1eec44b4ec3a2358388ceb6c87b677866f1f",
				  "raw_data":{
					  "contract":[
						 {"parameter":{"value":{"amount":1,"asset_name":"48756f6269546f6b656e","owner_address":"416b201fb7b9f2b97bbdaf5e0920191229767c30ee","to_address":"412451d09536fca47760ea6513372bbbbef8583105"},
								   "type_url":"type.googleapis.com/protocol.TransferAssetContract"},
						  "type":"TransferAssetContract"}
					  ],
					  "ref_block_bytes":"e1be",
					  "ref_block_hash":"8dbf5f0cf4c324f2",
					  "expiration":1540545294000,
					  "timestamp":1540545235358}
				 },
				 ...]
		 }
	*/
	Hash string // 这里采用 BlockID

	Previousblockhash string
	Height            uint64 `storm:"id"`
	Version           uint64
	Time              int64
	Fork              bool
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(json *gjson.Result, isTestnet bool) *Block

func (*Block) Blockheader

func (b *Block) Blockheader() *openwallet.BlockHeader

BlockHeader 区块链头

func (*Block) GetBlockHashID

func (block *Block) GetBlockHashID() string

func (*Block) GetHeight

func (block *Block) GetHeight() uint64

func (*Block) GetTransactions

func (block *Block) GetTransactions() []*Transaction

type Client

type Client struct {
	BaseURL string
	// AccessToken string
	Debug bool
	// contains filtered or unexported fields
}

A Client is a Tron RPC client. It performs RPCs over HTTP using JSON request and responses. A Client must be configured with a secret token to authenticate with other Cores on the network.

func NewClient

func NewClient(url, token string, debug bool) *Client

NewClient create new client to connect

func (*Client) Call

func (c *Client) Call(path string, param interface{}) (*gjson.Result, error)

Call calls a remote procedure on another node, specified by the path.

type Contract

type Contract struct {
	TxID            string
	BlockHash       string
	BlockHeight     uint64
	BlockTime       int64
	Type            string
	Parameter       gjson.Result
	Provider        []byte
	ContractName    []byte
	From            string
	To              string
	Amount          int64
	ContractAddress string
	SourceKey       string
	ContractRet     string
	Protocol        string
}

func NewContract

func NewContract(json gjson.Result, isTestnet bool) *Contract

type ContractDecoder

type ContractDecoder struct {
	*openwallet.SmartContractDecoderBase
	// contains filtered or unexported fields
}

func NewContractDecoder

func NewContractDecoder(wm *WalletManager) *ContractDecoder

NewContractDecoder 智能合约解析器

func (*ContractDecoder) GetTokenBalanceByAddress

func (decoder *ContractDecoder) GetTokenBalanceByAddress(contract openwallet.SmartContract, address ...string) ([]*openwallet.TokenBalance, error)

type ContractInfo

type ContractInfo struct {
	Bytecode                   string
	Name                       string
	ConsumeUserResourcePercent uint64
	ContractAddress            string
	ABI                        string
}

func NewContractInfo

func NewContractInfo(json *gjson.Result) *ContractInfo

type ExtractResult

type ExtractResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
	// contains filtered or unexported fields
}

ExtractResult 扫描完成的提取结果

type Result

type Result struct {
	Ret         string
	Fee         int64
	ContractRet string
}

func NewResult

func NewResult(json gjson.Result) *Result

type Return

type Return struct {
	Result  bool   `json:"result"`
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

func NewReturn

func NewReturn(json *gjson.Result) *Return

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult 保存结果

type SolidityParam

type SolidityParam struct {
	ParamType  string
	ParamValue interface{}
}

type Transaction

type Transaction struct {
	/*
		{
		    "ret": [
		        {
		            "contractRet": "SUCCESS"
		        }
		    ],
		    "signature": [
		        "b6fbefec182a1db9759104e3d5709343f25acc1866c77deb050d9bf0f6a5c3342237fbbf076377ea26d1a09edd46e599534a8499998814da0e9187e07260382001"
		    ],
		    "txID": "86b5a123b5cc50047532f1a55ed627f29012bba41e6590b0545f903289e7099a",
		    "raw_data": {
		        "contract": [
		            {
		                "parameter": {
		                    "value": {
		                        "amount": 10000,
		                        "owner_address": "415bdf283199369adb124f39dda845ae02c5d3eb5d",
		                        "to_address": "41bb65606e20dbdd7f0cfe6a66ae2858a6534f2d45"
		                    },
		                    "type_url": "type.googleapis.com/protocol.TransferContract"
		                },
		                "type": "TransferContract"
		            }
		        ],
		        "ref_block_bytes": "2298",
		        "ref_block_hash": "26478922abba48a0",
		        "expiration": 1551957595231
		    }
		}
	*/
	TxID        string
	BlockHash   string
	BlockHeight uint64
	BlockTime   int64
	IsCoinBase  bool
	Ret         []*Result
	Contract    []*Contract
}

func NewTransaction

func NewTransaction(json *gjson.Result, blockHash string, blockHeight uint64, blocktime int64, isTestnet bool) *Transaction

type TransactionDecoder

type TransactionDecoder struct {
	openwallet.TransactionDecoderBase
	// contains filtered or unexported fields
}

TransactionDecoder for Interface TransactionDecode

func NewTransactionDecoder

func NewTransactionDecoder(wm *WalletManager) *TransactionDecoder

NewTransactionDecoder 交易单解析器

func (*TransactionDecoder) CreateRawTransaction

func (decoder *TransactionDecoder) CreateRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

func (*TransactionDecoder) CreateSimpleSummaryRawTransaction

func (decoder *TransactionDecoder) CreateSimpleSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateSimpleSummaryRawTransaction 创建主币汇总交易

func (*TransactionDecoder) CreateSimpleTransaction

func (decoder *TransactionDecoder) CreateSimpleTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateRawTransaction 创建交易单

func (*TransactionDecoder) CreateSummaryRawTransaction

func (decoder *TransactionDecoder) CreateSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransaction, error)

CreateSummaryRawTransaction 创建汇总交易,返回原始交易单数组

func (*TransactionDecoder) CreateSummaryRawTransactionWithError added in v1.1.0

func (decoder *TransactionDecoder) CreateSummaryRawTransactionWithError(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateSummaryRawTransactionWithError 创建汇总交易,返回能原始交易单数组(包含带错误的原始交易单)

func (*TransactionDecoder) CreateTokenSummaryRawTransaction

func (decoder *TransactionDecoder) CreateTokenSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateTokenSummaryRawTransaction 创建代币汇总交易

func (*TransactionDecoder) CreateTokenTransaction

func (decoder *TransactionDecoder) CreateTokenTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateTokenTransaction 创建代币交易单

func (*TransactionDecoder) SignRawTransaction

func (decoder *TransactionDecoder) SignRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

SignRawTransaction 签名交易单

func (*TransactionDecoder) SubmitRawTransaction

func (decoder *TransactionDecoder) SubmitRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) (*openwallet.Transaction, error)

SubmitRawTransaction 广播交易单

func (*TransactionDecoder) VerifyRawTransaction

func (decoder *TransactionDecoder) VerifyRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单

type TransactionExtention

type TransactionExtention struct {
	Transaction    gjson.Result `json:"transaction" `
	Txid           string       `json:"txid"`
	ConstantResult []string     `json:"constant_result"`
	Result         *Return      `json:"result"`
}

func NewTransactionExtention

func NewTransactionExtention(json *gjson.Result) *TransactionExtention

type TronBlockScanner

type TronBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

	RescanLastBlockCount uint64 //重扫上N个区块数量
	// contains filtered or unexported fields
}

TronBlockScanner tron的区块链扫描器

func NewTronBlockScanner

func NewTronBlockScanner(wm *WalletManager) *TronBlockScanner

NewTronBlockScanner 创建区块链扫描器

func (*TronBlockScanner) BatchExtractTransaction

func (bs *TronBlockScanner) BatchExtractTransaction(blockHeight uint64, blockHash string, blockTime int64, txs []*Transaction) error

BatchExtractTransaction 批量提取交易单 bitcoin 1M的区块链可以容纳3000笔交易,批量多线程处理,速度更快

func (*TronBlockScanner) DeleteUnscanRecord

func (bs *TronBlockScanner) DeleteUnscanRecord(height uint64) error

DeleteUnscanRecord 删除指定高度的未扫记录

func (*TronBlockScanner) ExtractTransaction

func (bs *TronBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, blockTime int64, trx *Transaction, scanAddressFunc openwallet.BlockScanAddressFunc) ExtractResult

提取交易单

func (*TronBlockScanner) GetBalanceByAddress

func (bs *TronBlockScanner) GetBalanceByAddress(address ...string) ([]*openwallet.Balance, error)

GetAssetsAccountBalanceByAddress 查询账户相关地址的交易记录

func (*TronBlockScanner) GetCurrentBlockHeader

func (bs *TronBlockScanner) GetCurrentBlockHeader() (*openwallet.BlockHeader, error)

GetCurrentBlockHeader 获取当前区块高度

func (*TronBlockScanner) GetGlobalMaxBlockHeight

func (bs *TronBlockScanner) GetGlobalMaxBlockHeight() uint64

func (*TronBlockScanner) GetLocalBlock

func (bs *TronBlockScanner) GetLocalBlock(height uint64) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*TronBlockScanner) GetLocalNewBlock

func (bs *TronBlockScanner) GetLocalNewBlock() (uint64, string)

GetLocalNewBlock 获取本地记录的区块高度和hash

func (*TronBlockScanner) GetScannedBlockHeight

func (bs *TronBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*TronBlockScanner) GetSourceKeyByAddress

func (bs *TronBlockScanner) GetSourceKeyByAddress(address string) (string, bool)

GetSourceKeyByAddress 获取地址对应的数据源标识

func (*TronBlockScanner) InitTronExtractResult

func (bs *TronBlockScanner) InitTronExtractResult(tx *Contract, result *ExtractResult, operate int64)

InitTronExtractResult operate = 0: 输入输出提取,1: 输入提取,2:输出提取

func (*TronBlockScanner) RescanFailedRecord

func (bs *TronBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*TronBlockScanner) Restart

func (bs *TronBlockScanner) Restart() error

Restart 继续扫描

func (*TronBlockScanner) Run

func (bs *TronBlockScanner) Run() error

Run 运行

func (*TronBlockScanner) SaveLocalBlock

func (bs *TronBlockScanner) SaveLocalBlock(block *Block)

SaveLocalBlock 记录本地新区块

func (*TronBlockScanner) SaveLocalNewBlock

func (bs *TronBlockScanner) SaveLocalNewBlock(blockHeight uint64, blockHash string)

SaveLocalNewBlock 记录区块高度和hash到本地

func (*TronBlockScanner) SaveUnscanRecord

func (bs *TronBlockScanner) SaveUnscanRecord(record *UnscanRecord) error

SaveUnscanRecord 保存交易记录到钱包数据库

func (*TronBlockScanner) ScanBlock

func (bs *TronBlockScanner) ScanBlock(height uint64) error

ScanBlock 扫描指定高度区块

func (*TronBlockScanner) ScanBlockTask

func (bs *TronBlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*TronBlockScanner) SetRescanBlockHeight

func (bs *TronBlockScanner) SetRescanBlockHeight(height uint64) error

SetRescanBlockHeight 重置区块链扫描高度

func (*TronBlockScanner) Stop

func (bs *TronBlockScanner) Stop() error

//Stop 停止扫描

type UnscanRecord

type UnscanRecord struct {
	ID          string `storm:"id"` // primary key
	BlockHeight uint64
	TxID        string
	Reason      string
}

UnscanRecords 扫描失败的区块及交易

func NewUnscanRecord

func NewUnscanRecord(height uint64, txID, reason string) *UnscanRecord

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol    string
	MasterKey string

	//RPCUser RPC认证账户名
	RPCUser string
	//RPCPassword RPC认证账户密码
	RPCPassword string
	//证书目录
	CertsDir string

	//rpc证书
	CertFileName string
	//区块链数据文件
	BlockchainFile string
	//是否测试网络
	IsTestNet bool
	// 核心钱包是否只做监听
	CoreWalletWatchOnly bool
	//最大的输入数量
	MaxTxInputs int

	//钱包服务API
	ServerAPI string
	//钱包安装的路径
	NodeInstallPath string
	//钱包数据文件目录
	WalletDataPath string
	//汇总阀值
	Threshold decimal.Decimal
	//汇总地址
	SumAddress string
	//汇总执行间隔时间
	CycleSeconds time.Duration
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//小数位长度
	CoinDecimal decimal.Decimal
	//后台数据源类型
	RPCServerType int
	//FeeLimit 智能合约最大能量消耗限制,1 Energy = 10 SUN
	FeeLimit int64
	//FeeMini 智能合约最小能量消耗起,1 Energy = 10 SUN
	FeeMini int64
	// contains filtered or unexported fields
}

WalletConfig configs for Wallet

func NewConfig

func NewConfig() *WalletConfig

NewConfig Create config instance

func (*WalletConfig) InitConfig

func (wc *WalletConfig) InitConfig()

InitConfig 初始化配置文件

func (*WalletConfig) PrintConfig

func (wc *WalletConfig) PrintConfig() error

PrintConfig Print config information

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase

	Config         *WalletConfig          //钱包管理配置
	Storage        *hdkeystore.HDKeystore //秘钥存取
	FullnodeClient *Client                // 全节点客户端
	WalletClient   *Client                // 节点客户端
	Log            *log.OWLogger          //日志工具

	WalletsInSum map[string]*openwallet.Wallet //参与汇总的钱包

	Blockscanner    *TronBlockScanner               //区块扫描器
	AddrDecoder     openwallet.AddressDecoder       //地址编码器
	TxDecoder       openwallet.TransactionDecoder   //交易单编码器
	ContractDecoder openwallet.SmartContractDecoder //
}

WalletManager struct

func NewWalletManager

func NewWalletManager() *WalletManager

NewWalletManager create instance

func (*WalletManager) BackupWalletFlow

func (wm *WalletManager) BackupWalletFlow() error

备份钱包流程

func (*WalletManager) BroadcastTransaction

func (wm *WalletManager) BroadcastTransaction(raw string) (string, error)

func (*WalletManager) BroadcastTransaction1

func (wm *WalletManager) BroadcastTransaction1(raw string) error

BroadcastTransaction Done! Function:Broadcast the signed transaction

demo:curl -X POST http://127.0.0.1:8090/wallet/broadcasttransaction -d ‘
	{“signature”:[“97c825b41c77de2a8bd65b3df55cd4c0df59c307c0187e42321dcc1cc455ddba583dd9502e17cfec5945b34cad0511985a6165999092a6dec84c2bdd97e649fc01”],
	 ”txID”:”454f156bf1256587ff6ccdbc56e64ad0c51e4f8efea5490dcbc720ee606bc7b8”,
	 ”raw_data”:{“contract”:[{
		 				“parameter”:{
							“value”:{“amount”:1000,
								   ”owner_address”:”41e552f6487585c2b58bc2c9bb4492bc1f17132cd0”,
								   ”to_address”:   ”41d1e7a6bc354106cb410e65ff8b181c600ff14292”},
							”type_url”:”type.googleapis.com/protocol.TransferContract”},
						”type”:”TransferContract”
					}],
			”ref_block_bytes”:”267e”,
			”ref_block_hash”:”9a447d222e8de9f2”,
			”expiration”:1530893064000,
			”timestamp”:1530893006233}
	}’

Parameters:Signed Transaction contract data Return value:broadcast success or failure

func (*WalletManager) CreateAccount

func (wm *WalletManager) CreateAccount(ownerAddress, accountAddress string) (txRaw *gjson.Result, err error)

CreateAccount Done! Function:Create an account. Uses an already activated account to create a new account demo:curl -X POST http://127.0.0.1:8090/wallet/createaccount -d ‘

{
	“owner_address”:”41d1e7a6bc354106cb410e65ff8b181c600ff14292”,
	“account_address”: “41e552f6487585c2b58bc2c9bb4492bc1f17132cd0”
}’

Parameters:

Owner_address is an activated account,converted to a hex String;
account_address is the address of the new account, converted to a hex string, this address needs to be calculated in advance

Return value:Create account Transaction raw data

func (*WalletManager) CreateAddress

func (wm *WalletManager) CreateAddress(passValue string) (addr string, err error)

CreateAddress Done! Function: Create address from a specified password string (NOT PRIVATE KEY) Demo: curl -X POST http://127.0.0.1:8090/wallet/createaddress -d ‘

{“value”: “7465737470617373776f7264” }’

Parameters:

value is the password, converted from ascii to hex

Return value:

value is the corresponding address for the password, encoded in hex.
Convert it to base58 to use as the address.

Warning:

Please control risks when using this API. To ensure environmental security, please do not invoke APIs provided by other or invoke this very API on a public network.

func (*WalletManager) CreateAddressFlow

func (wm *WalletManager) CreateAddressFlow() error

创建地址流程

func (*WalletManager) CreateAddressRef

func (wm *WalletManager) CreateAddressRef(key []byte, isPrivate bool) (addr string, err error)

CreateAddressRef Done! Function: Create address from a specified private key string

func (*WalletManager) CreateBatchAddress

func (wm *WalletManager) CreateBatchAddress(name, password string, count uint64) (string, []*openwallet.Address, error)

CreateBatchAddress 批量创建地址

func (*WalletManager) CreateNewWallet

func (wm *WalletManager) CreateNewWallet(name, password string) (*openwallet.Wallet, string, error)

CreateNewWallet 创建钱包

func (*WalletManager) CreateTokenTransaction

func (wm *WalletManager) CreateTokenTransaction(toAddress, ownerAddress string, amount string, contract openwallet.SmartContract) (txRawHex string, err error)

func (*WalletManager) CreateTransaction

func (wm *WalletManager) CreateTransaction(toAddress, ownerAddress string, amount float64) (raw string, err error)

CreateTransaction Writing! Function:Creates a transaction of transfer. If the recipient address does not exist, a corresponding account will be created on the blockchain. demo: curl -X POST http://127.0.0.1:8090/wallet/createtransaction -d ‘

{“to_address”: “41e9d79cc47518930bc322d9bf7cddd260a0260a8d”,
“owner_address”: “41D1E7A6BC354106CB410E65FF8B181C600FF14292”,
“amount”: 1000 }’ P

Parameters:

To_address is the transfer address, converted to a hex string;
owner_address is the transfer transfer address, converted to a hex string;
amount is the transfer amount

Return value:

Transaction contract data

func (*WalletManager) CreateTransactionRef

func (wm *WalletManager) CreateTransactionRef(toAddress, ownerAddress string, amount string) (txRawHex string, err error)

Deprecated

func (*WalletManager) CreateWalletFlow

func (wm *WalletManager) CreateWalletFlow() error

创建钱包流程

func (*WalletManager) CurveType

func (wm *WalletManager) CurveType() uint32

CurveType 曲线类型

func (*WalletManager) Decimal

func (wm *WalletManager) Decimal() int32

Decimal 小数位精度 *1000000

func (*WalletManager) DeleteUnscanRecord

func (wm *WalletManager) DeleteUnscanRecord(height uint64) error

DeleteUnscanRecord 删除指定高度的未扫记录

func (*WalletManager) DeleteUnscanRecordNotFindTX

func (wm *WalletManager) DeleteUnscanRecordNotFindTX() error

DeleteUnscanRecordNotFindTX 删除未没有找到交易记录的重扫记录

func (*WalletManager) FullName

func (wm *WalletManager) FullName() string

FullName 币种全名

func (*WalletManager) GenerateAddress

func (wm *WalletManager) GenerateAddress() (address map[string]string, err error)

GenerateAddress Done! Function: Generates a random private key and address pair Demo:curl -X POST -k http://127.0.0.1:8090/wallet/generateaddress Parameters:

no parameters.

Return value:

value is the corresponding address for the password, encoded in hex.
Convert it to base58 to use as the address.

Warning:

Please control risks when using this API.
To ensure environmental security, please do not invoke APIs provided by other or invoke this very API on a public network.

func (*WalletManager) GetAccount

func (wm *WalletManager) GetAccount(address string) (account *openwallet.AssetsAccount, err error)

deprecated GetAccount Done! Function:Query bandwidth information. Parameters:

Account address,converted to a base64 string

Return value:

func (*WalletManager) GetAccountNet

func (wm *WalletManager) GetAccountNet(address string) (accountNet *AccountNet, err error)

GetAccountNet Done! Function:Query bandwidth information. demo: curl -X POST http://127.0.0.1:8090/wallet/getaccountnet -d ‘

{“address”: “4112E621D5577311998708F4D7B9F71F86DAE138B5”}’

Parameters:

Account address,converted to a hex string

Return value:

Bandwidth information for the account.
If a field doesn’t appear, then the corresponding value is 0.
{“freeNetUsed”: 557,”freeNetLimit”: 5000,”NetUsed”: 353,”NetLimit”: 5239157853,”TotalNetLimit”: 43200000000,”TotalNetWeight”: 41228}

func (*WalletManager) GetAccountResource added in v1.1.0

func (wm *WalletManager) GetAccountResource(address string) (*AccountResource, error)

GetAccountResource

func (*WalletManager) GetAddressDecode

func (wm *WalletManager) GetAddressDecode() openwallet.AddressDecoder

GetAddressDecode 地址解析器

func (*WalletManager) GetAddressWithBalance

func (wm *WalletManager) GetAddressWithBalance(address ...*openwallet.Address) error

GetAddressWithBalance 获取地址对应的余额

func (*WalletManager) GetAddressesFromLocalDB

func (wm *WalletManager) GetAddressesFromLocalDB(walletID string, offset, limit int) ([]*openwallet.Address, error)

GetAddressesFromLocalDB 从本地数据库

func (*WalletManager) GetAssetsLogger

func (wm *WalletManager) GetAssetsLogger() *log.OWLogger

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlockByID

func (wm *WalletManager) GetBlockByID(blockID string) (block *Block, err error)

GetBlockByID Done! Function:Query block by ID

demo: curl -X POST http://127.0.0.1:8090/wallet/getblockbyid -d ‘
	{“value”: “0000000000038809c59ee8409a3b6c051e369ef1096603c7ee723c16e2376c73”}’

Parameters:Block ID. Return value:Block Object

func (*WalletManager) GetBlockByLatestNum

func (wm *WalletManager) GetBlockByLatestNum(num uint64) (blocks []*Block, err error)

GetBlockByLatestNum Done! Function:Query the latest blocks

demo: curl -X POST http://127.0.0.1:8090/wallet/getblockbylatestnum -d ‘
	{“num”: 5}’

Parameters:The number of blocks to query Return value:A list of Block Objects

func (*WalletManager) GetBlockByLimitNext

func (wm *WalletManager) GetBlockByLimitNext(startNum, endNum uint64) (blocks []*Block, err error)

GetBlockByLimitNext Done! Function:Query a range of blocks by block height

demo: curl -X POST http://127.0.0.1:8090/wallet/getblockbylimitnext -d ‘
	{“startNum”: 1, “endNum”: 2}’

Parameters:

startNum:Starting block height, including this block
endNum:Ending block height, excluding that block

Return value:A list of Block Objects

func (*WalletManager) GetBlockByNum

func (wm *WalletManager) GetBlockByNum(num uint64) (block *Block, error error)

GetBlockByNum Done! Function:Query block by height

demo: curl -X POST http://127.0.0.1:8090/wallet/getblockbynum -d ‘
	{“num” : 100}’

Parameters:

Num is the height of the block

Return value:specified Block object

func (*WalletManager) GetBlockScanner

func (wm *WalletManager) GetBlockScanner() openwallet.BlockScanner

GetBlockScanner 获取区块链

func (*WalletManager) GetContractInfo

func (wm *WalletManager) GetContractInfo(contractAddress string) (*ContractInfo, error)

GetContractInfo 获取智能合约信息

func (*WalletManager) GetCurrentBlock

func (wm *WalletManager) GetCurrentBlock() (block *Block, err error)

func (*WalletManager) GetNowBlock

func (wm *WalletManager) GetNowBlock() (block *Block, err error)

GetNowBlock Done! Function:Query the latest block

demo: curl -X POST http://127.0.0.1:8090/wallet/getnowblock

Parameters:None Return value:Latest block on full node

func (*WalletManager) GetPrivateKeyRef

func (wm *WalletManager) GetPrivateKeyRef(walletID, password string, index uint64, serializes uint32) (string, error)

GetPrivateKeyRef 找到地址索引对应的私钥,返回私钥hex格式字符串

func (*WalletManager) GetSmartContractDecoder

func (this *WalletManager) GetSmartContractDecoder() openwallet.SmartContractDecoder

func (*WalletManager) GetTRC10Balance

func (wm *WalletManager) GetTRC10Balance(address string, tokenID string) (int64, error)

GetTokenBalance 获取代币余额

func (*WalletManager) GetTRC20Balance

func (wm *WalletManager) GetTRC20Balance(address string, contractAddress string) (int64, error)

GetTokenBalance 获取代币余额

func (*WalletManager) GetTRXAccount

func (wm *WalletManager) GetTRXAccount(address string) (account *Account, err error)

GetAccount Done! Function:Query bandwidth information. Parameters:

Account address,converted to a base64 string

Return value:

func (*WalletManager) GetTotalTransaction

func (wm *WalletManager) GetTotalTransaction() (num uint64, err error)

GetTotalTransaction Done! Function:Count all transactions (number) on the network demo: curl -X POST http://127.0.0.1:8090/wallet/totaltransaction Parameters:Nones Return value:

Total number of transactions.

func (*WalletManager) GetTransaction

func (wm *WalletManager) GetTransaction(txid string, blockhash string, blockheight uint64, blocktime int64) (*Transaction, error)

func (*WalletManager) GetTransactionDecoder

func (wm *WalletManager) GetTransactionDecoder() openwallet.TransactionDecoder

GetTransactionDecoder 交易单解析器

func (*WalletManager) GetTransactionFeeEstimated

func (wm *WalletManager) GetTransactionFeeEstimated(from string, data string) (*txFeeInfo, error)

GetTransactionFeeEstimated 预计手续费

func (*WalletManager) GetTransactionSign

func (wm *WalletManager) GetTransactionSign(transaction, privateKey string) (rawSinged []byte, err error)

Writing! No used! Function:Sign the transaction, the api has the risk of leaking the private key, please make sure to call the api in a secure environment

demo: curl -X POST http://127.0.0.1:8090/wallet/gettransactionsign -d ‘
	{ “transaction” : {“txID”:”454f156bf1256587ff6ccdbc56e64ad0c51e4f8efea5490dcbc720ee606bc7b8”,
				 ”raw_data”:{
					“contract”:[{“parameter”:{“value”:{“amount”:1000,
										     ”owner_address”:”41e552f6487585c2b58bc2c9bb4492bc1f17132cd0”,
										     ”to_address”:”41d1e7a6bc354106cb410e65ff8b181c600ff14292”},
									  ”type_url”:”type.googleapis.com/protocol.TransferContract”},
							 ”type”:”TransferContract”}],
					”ref_block_bytes”:”267e”,
					”ref_block_hash”:”9a447d222e8de9f2”,
					”expiration”:1530893064000,
					”timestamp”:1530893006233}}
	“privateKey” : “your private key”} }’

Parameters:

Transaction is a contract created by http api,
privateKey is the user private key

Return value:Signed Transaction contract data

func (*WalletManager) GetUnscanRecords

func (wm *WalletManager) GetUnscanRecords() ([]*UnscanRecord, error)

获取未扫记录

func (*WalletManager) GetWalletBalance

func (wm *WalletManager) GetWalletBalance(accountID string) string

GetWalletBalance 获取钱包余额

func (*WalletManager) GetWalletInfo

func (wm *WalletManager) GetWalletInfo(walletID string) (*openwallet.Wallet, error)

GetWalletInfo 获取钱包列表

func (*WalletManager) GetWalletList

func (wm *WalletManager) GetWalletList() error

GetWalletList 获取钱包列表

func (*WalletManager) GetWallets

func (wm *WalletManager) GetWallets() ([]*openwallet.Wallet, error)

GetWallets 获取钱包列表

func (*WalletManager) Getbalance

func (wm *WalletManager) Getbalance(address string) (*AddrBalance, error)

deprecated

func (*WalletManager) ImportWatchOnlyAddress

func (wm *WalletManager) ImportWatchOnlyAddress(address ...*openwallet.Address) error

ImportWatchOnlyAddress 导入观测地址

func (*WalletManager) InitConfigFlow

func (wm *WalletManager) InitConfigFlow() error

初始化配置流程

func (*WalletManager) IsEnoughEnergyToTransferTRC20 added in v1.1.0

func (wm *WalletManager) IsEnoughEnergyToTransferTRC20(address string, trxBalance *big.Int) (flag bool, energyRest int64, feeMini int64)

IsEnoughEnergyToTransferTRC20 是否足够能量转账TRC20

func (*WalletManager) ListNodes

func (wm *WalletManager) ListNodes() (nodes []string, err error)

ListNodes Writing! Function:

List the nodes which the api fullnode is connecting on the network

demo:

curl -X POST http://127.0.0.1:8090/wallet/listnodes

Parameters:None Return value:List of nodes

func (*WalletManager) ListWitnesses

func (wm *WalletManager) ListWitnesses() (witnesses string, err error)

ListWitnesses Writing! Function:

Query the list of Super Representatives

demo:

curl -X POSThttp://127.0.0.1:8090/wallet/listwitnesses

Parameters:None Return value:List of all Super Representatives

func (*WalletManager) LoadAssetsConfig

func (wm *WalletManager) LoadAssetsConfig(c config.Configer) error

LoadAssetsConfig 加载外部配置

func (*WalletManager) LoadConfig

func (wm *WalletManager) LoadConfig() error

LoadConfig 读取配置

func (*WalletManager) RestoreWalletFlow

func (wm *WalletManager) RestoreWalletFlow() error

RestoreWalletFlow 恢复钱包流程

func (*WalletManager) SendTransaction

func (wm *WalletManager) SendTransaction(walletID, to string, amount decimal.Decimal, password string, feesInSender bool) ([]string, error)

SendTransaction 发送交易

func (*WalletManager) ShowConfig

func (wm *WalletManager) ShowConfig() error

查看配置信息

func (*WalletManager) SignTransactionRef

func (wm *WalletManager) SignTransactionRef(hash string, privateKey string) (signedTxRaw string, err error)

func (*WalletManager) SummaryFollow

func (wm *WalletManager) SummaryFollow() error

SummaryFollow 汇总流程

func (*WalletManager) SummaryWallets

func (wm *WalletManager) SummaryWallets()

SummaryWallets 执行汇总流程

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

func (*WalletManager) TransferFlow

func (wm *WalletManager) TransferFlow() error

SendTXFlow 发送交易

func (*WalletManager) TriggerSmartContract

func (wm *WalletManager) TriggerSmartContract(
	contractAddress string,
	function string,
	parameter string,
	feeLimit uint64,
	callValue uint64,
	ownerAddress string) (*TransactionExtention, error)

TriggerSmartContract 初始智能合约方法

func (*WalletManager) UpdateAccount

func (wm *WalletManager) UpdateAccount(accountName, ownerAddress string) (tx *gjson.Result, err error)

UpdateAccount Done! Function:Modify account name demo:curl -X POSThttp://127.0.0.1:8090/wallet/updateaccount -d ‘

{
	“account_name”: “0x7570646174654e616d6531353330383933343635353139” ,
	”owner_address”:”41d1e7a6bc354106cb410e65ff8b181c600ff14292”
}’

Parameters:

account_name is the name of the account, converted into a hex string;
owner_address is the account address of the name to be modified, converted to a hex string.

Return value:modified Transaction Object

func (*WalletManager) ValidSignedTokenTransaction

func (wm *WalletManager) ValidSignedTokenTransaction(txHex string) error

func (*WalletManager) ValidSignedTransactionRef

func (wm *WalletManager) ValidSignedTransactionRef(txHex string) error

Deprecated

func (*WalletManager) ValidateAddress

func (wm *WalletManager) ValidateAddress(address string) (err error)

ValidateAddress Done! Function:validate address Demo: curl -X POST http://127.0.0.1:8090/wallet/validateaddress -d ‘

{“address”: “4189139CB1387AF85E3D24E212A008AC974967E561”}’

Parameters:

The address, should be in base58checksum, hexString or base64 format.

Return value: ture or false

Directories

Path Synopsis
grpc-gateway
api
Package api is a reverse proxy.
Package api is a reverse proxy.

Jump to

Keyboard shortcuts

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