# Java SDK

# 快速开始

实例化"topj"。

package org.topnetwork;


import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class main {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
         }
}

# 网络

TOP AI Network Java SDK提供了RPC、Restful接口。

  • RPC接口

    HttpService httpService = new HttpService(serverUrl);
    
  • Restful接口

    HttpService httpService = new HttpService(serverUrl);
    

# 接口总览

接口 描述
topj.setTransactionReceiptProcessor() 交易初始化设置。
topj.genAccount() 根据私钥生成account账户对象。
topj.passport() 获取链上访问身份令牌。
topj.getChainInfo() 获取主链信息。
topj.getAllStandBys() 获取候选池所有节点信息。
topj.getStandBys() 获取候选池单个节点信息。
topj.getCGP() 获取链上治理参数。
topj.getLastUnitBlock()topj.getUnitBlockByHeight() 获取最新区块高度或者指定区块高度的unit block。
topj.getLastTableBlock()topj.getTableBlockByHeight() 获取最新区块高度或者指定区块高度的table block。
topj.getAccount() 获取链上账户信息。
topj.transfer() 将TOP转到另外一个账户地址。
topj.getTransaction() 获取账户交易详情。
topj.stakeGas() 锁定TOP token兑换gas。
topj.unStakeGas() 解锁兑换gas的TOP token。
topj.registerNode() 注册矿工。
topj.queryNodeInfo() 查询矿工信息。
topj.updateNodeType() 更新矿工类型。
topj.setNodeName() 设置矿工昵称。
topj.stakeDeposit() 增加矿工保证金。
topj.unStakeDeposit() 减少矿工保证金。
topj.setDividendRate() 高级矿工设置分红比例。
topj.listVoteUsed() 获取账户投票分布。
topj.unRegisterNode() 注销矿工。
topj.redeemNodeDeposit() 矿工注销后赎回矿工保证金。
topj.stakeVote() 锁定TOP token兑换选票。
topj.unStakeVote() 解锁兑换选票的TOP token。
topj.voteNode() 投票。
topj.unVoteNode() 取消投票。
topj.queryVoterDividend() 获取投票者分红信息。
topj.claimVoterDividend() 领取投票者分红。
topj.queryNodeReward() 获取单个矿工奖励信息。
topj.queryAllNodeReward() 获取所有矿工奖励信息。
topj.claimNodeReward() 领取矿工奖励。
topj.submitProposal() 提交提案。
topj.withdrawProposal() 撤回提案。
topj.queryProposal() 获取提案详情。
topj.tccVote() TCC表决提案。
工具方法 描述
解析出转账交易体中的amount和note数据 解析出转账交易体中的amount和note数据。
判断交易是否成功 判断交易是否成功。
交易体对象说明 所有交易请求都返回该对象。

# 交易初始化设置

SDK发送交易请求后,请求无法直接返回交易执行结果,所以需要循环去链上查询交易是否成功,默认每3秒查询一次,循环100次,共5分钟。如果此时交易仍查询不到,则程序返回交易hash。

“setTransactionReceiptProcessor”方法可以修改循环查询间隔以及循环次数,比如示例代码中修改为每5秒查询一次,循环3次,共15秒。

请求方式

topj.setTransactionReceiptProcessor

请求参数

"TransactionReceiptProcessor"为抽象类,有"PollingTransactionReceiptProcessor"和"NoOpProcessor"两个实现类,可实例化这两个类并传入。

"PollingTransactionReceiptProcessor"表示会轮询"attempts"次,每次间隔"sleepDuration"毫秒。

实例化所需参数如下表所示。

参数名称 是否必选 默认值 类型 说明
sleepDuration - Long 等待间隔,单位“毫秒”。
attempts - Int 循环次数。

也可设置不循环,直接返回交易hash,传入"NoOpProcessor"对象接口,代码为:

topj.setTransactionReceiptProcessor(new NoOpProcessor())

"NoOpProcessor"表示直接返回hash,无须参数。

请求样例

package org.topnetwork;

import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class SetTransactionReceiptProcessor {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://192.168.50.159:19081");
        topj = Topj.build(httpService);
        PollingTransactionReceiptProcessor transactionReceiptProcessor = new PollingTransactionReceiptProcessor(5000, 5);
        topj.setTransactionReceiptProcessor(transactionReceiptProcessor);
    }
}

# 链基础操作

# 根据私钥生成account账户对象

本地根据私钥生成账户对象,对象中包含私钥、公钥、地址等参数。

请求方法

topj.genAccount

请求参数

参数名称 是否必选 默认值 类型 说明
privateKey - String 私钥。

返回参数

参数名称 类型 说明
address String 账户地址。
balance Uint64 账户余额。
lastUnitHeight Uint64 最新共识成功的交易的unit block高度。
netType Integer 网络类型,"0"--主网、"1"--测试网。
nonce Uint64 该账户最新共识成功的交易序号,唯一。
privateKey String 私钥用于解密和交易签名。
请不要与其他人分享您的私钥,以免造成资产损失!
privateKeyBytes String 私钥的Byte格式。
publicKey String 公钥,和私钥总是成对出现。
用于加密及验签。
sequenceId String 客户端会话次数,递增。

本地生成 account 主要用于生成公私钥和地址,其他参数,除了“token",均为初始值,需调用 topjs.getAccount 方法获取链上真实值。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.procotol.http.HttpService;

public class GenAccount {
    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args){
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        account = topj.genAccount();
        System.out.println(account.getPublicKey() + "......" + account.getPrivateKey() + "..........."+ account.getAddress());
        String os = JSON.toJSONString(account);
        System.out.println(os);
    }
}

返回样例

{
	"address": "T8000010eaeb3a8f2e34b36d34d41e1efeeb1bb7f5c1f9",
	"balance": 0,
	"lastUnitHeight": 0,
	"netType": 0,
	"nonce": 0,
	"privateKey": "071c178f9b5cd200fae90e582d4e68f5469343d87e52d29e5b8dc4dd6f8c554b",
	"privateKeyBytes": "BxwXj5tc0gD66Q5YLU5o9UaTQ9h+UtKeW43E3W+MVUs=",
	"publicKey": "145cb2e8f896f631c0cf5ea831d79a7e6444bc288f9bdf9a1ec0280e512cd87945c4214c4f1bf4cbf0d3f42ef1e2de72e4bfc628eae28b5360a0152ca947e6a9",
	"sequenceId": "4572172267121319642"
}

# 获取链上访问身份令牌

根据账户获取identity token(身份令牌),每个账户token不同。在后续所有的请求中,都需要token参数。

请求方法

topj.passport

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。

返回参数

返回值中包含token字段,已直接放入account对象中,供后续调用时使用。

参数名称 类型 说明
secret_key String 密钥key。
signature_method String 签名方法。
signature_ver_code String 签名方法版本号。
identity_token String 身份令牌,用于和主链节点交互,后续所有请求都需要该参数。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.PassportResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class PassPort {

    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        ResponseBase<PassportResponse> token =topj.passport(account);
        System.out.println(JSON.toJSONString(token));
    }
}

返回样例

{
	"data": {
		"identity_token": "62295a21-b338-45bd-a6de-96ff47371482",
		"secret_key": "ec6b265c-36be-4995-b5fa-b5e6476d6228",
		"signature_method": "hmac_sha2",
		"signature_ver_code": "1.0"
	},
	"errmsg": "OK",
	"errno": 0,
	"sequence_id": "-6181715942575529103"
}

# 获取主链信息

请求方法

topj.getChainInfo

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。

返回参数

参数名称 类型 说明
first_timerblock_hash String 第一个时钟块hash。
first_timerblock_stamp Uint64 第一个时钟块生成时间。
init_total_locked_token Uint64 系统初始化总TOP token锁定金额,系统初始化gas兑换率=系统总gas/总锁定金额,避免系统初始化gas兑换率为0。
token_price Uint64 锁定TOP token兑换gas的兑换率,单位tgas/top。
total_gas_shard Uint32 单片24小时总gas量。
validator_group_count Uint32 validator group 数量,当前默认为4。
network_activate_time uint64 主网激活时间。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ChainInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetChainInfo {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        System.out.println(JSONObject.toJSON(account.getBalance()));
        ResponseBase<ChainInfoResponse> chainInfo = topj.getChainInfo(account);
        System.out.println(JSONObject.toJSON(chainInfo));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"token_price": "8640",
		"network_activate_time": 1,
		"init_total_locked_token": 1000000000000000,
		"validator_group_count": "4",
		"total_gas_shard": "2160000000000",
		"first_timerblock_stamp": "1573189200",
		"first_timerblock_hash": "72fe32a913ce06c6e1942f51ee6ad33682588baca7c75de56622474ed41df9f1"
	},
	"sequence_id": "-5300293571980210978",
	"errmsg": "OK"
}

# 获取候选池所有节点

请求方法

topj.getAllStandBys

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。

返回参数

参数名称 类型 说明
consensus_public_key String 矿工工作时使用的key。账户公私钥对或者无资产公私钥对。
node_id String 矿工账户地址。
stake Uint64 节点权益。
program_version String 程序版本。
is_genesis_node String 是否为创世节点。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.StandBysResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetAllStandBys {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        System.out.println(account.getAddress());
        topj.passport(account);
        ResponseBase<StandBysResponse> s = topj.getAllStandBys(account);
        System.out.println(JSONObject.toJSON(s));
    }


}

返回样例

{
	"errno": 0,
	"data": {
		"activated_state": "activated",
		"edge": [{
			"stake": 0,
			"consensus_public_key": "BDrdTUhkR5+biKfgqhG2AjdzTqcJeLerhUzvAMAVQucqaVThKs0TsEBGrMZddvnc/5ObxHt80NqbFWS3o+S0uBo=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000LKvLi6cVAHQEV12ZebsQC9n3RGzJVr1dbx"
		}],
		"auditor": [{
			"stake": 1128237,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}],
		"validator": [{
			"stake": 1062,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 406,
			"consensus_public_key": "BLdLvnf1PANd4CwDCd7evDM00QHle+XzsVnxgHqaNyV1XVvAPGIIptXjF+fVBpDy9ouA/4vUh7wUykbeTPb4f+g=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000Li1eU7Ngm2qKhbeToGdP84yxVnP7aWEdDM"
		}],
		"archive": [{
			"stake": 0,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}],
		"root_beacon": [{
			"stake": 3418900,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}]
	},
	"sequence_id": "6362420583714881307",
	"errmsg": "OK"
}

# 获取候选池单个节点信息

请求方法

topj.getStandBys

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。
nodeAddr - String 矿工账户地址。

返回参数

参数名称 类型 说明
node_sign_key String 矿工注册时使用的公钥。账户公钥或者无资产的公私钥对中的公钥。
node_account_address String 矿工账户地址。
stake Uint64 节点权益。
program_version string 程序版本。
is_genesis_node bool 是否为创世节点。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.StandBysDetail;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetStandBys {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        ResponseBase<StandBysDetail> sb = topj.getStandBys(account, "T00000LYHXC2soSmkvcySdKqc56FBh5XMUeAbqsd");
        System.out.println(JSONObject.toJSON(sb));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"stake": 0,
		"consensus_public_key": "BFj83APhuMt425X26Dix9iuErAi0XjRklXbZpxghqRT/JZwDUg5saEgBeQmJOW0EW8ITFAp/Ld8ElEq594o/KSA=",
		"program_version": "1.1.0",
		"is_genesis_node": "true",
		"node_id": "T00000LYHXC2soSmkvcySdKqc56FBh5XMUeAbqsd"
	},
	"sequence_id": "981421573870353020",
	"errmsg": "OK"
}

# 获取链上治理参数

请求方法

topj.getCGP

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。

返回参数

请参见链上治理参数

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.CGPResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetCGP {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        ResponseBase<CGPResponse> cgp = topj.getCGP(account);
        System.out.println(JSONObject.toJSON(cgp));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"min_tx_deposit": "100000",
		"backward_node_lock_duration_increment": "103680",
		"rec_election_interval": "259201",
		"votes_report_interval": "30",
		"zone_election_trigger_interval": "181",
		"edge_election_interval": "360",
		"toggle_whitelist": "0",
		"election_rotation_count_ratio": "8",
		"unlock_gas_staked_delay_time": "8640",
		"whitelist": "T00000LabjxtsmwfhVW7RK1ezUZNUMdKUv6gxTG5,T00000LZgWW5jsGR4Bg62ZZWbncioWQKDRXtVyJN,T00000LNTsgQq8sGgXmJSNMqEpze9bnqjrTpbk4K,T00000LZtiM94bYBmiC5261Y6MnggQNTjyrFb6Ja,T00000LaPL3pVbkxEfE8wSCanWFtnBVoQaxWkejS,T00000LUkbBh9rPA1RFcbKrJbwj5uQgHK93ADJAW,T00000LcvZaypD3bHFHHh4PsXsy5ASDGAD4mmpFr,T00000LbgaCLnuxnqaqPh8e9EpeNqsRju6MuCr4z,T00000LSmt4xfNdC2v8xQHRSbfSQ7b5aC1UTXWfo,T00000LcM8Pn37SRF5RaTHZLsRW4wudDVE9BAXy8,T00000Lg24i2TweBikod4UJwmMS8TqgwvHooFYMp,T00000LZiwnEtvrRaxEVNoZxU6mp1CFFwvA3JRhQ,T00000LS2WKtMuE7moMekoiYhk78rdFYvJzayMDK,T00000LZkFxsyiz8nJuruAzdtvi8YhZpmL2U9dXK,T00000LMxyqFyLC5ZWhH9AWdgFcK4bbL1kxyw11W,T00000LhXXoXe5KD6furgsEKJRpT3SuZLuN1MaCf,T00000LgspJnjWPFMwqrMF7KHi3rQKQLYp8E1Yxz,T00000LYpGz3V6QJ52SGumo1yWwX7LyxrQqjDLdq,T00000LQnwSvLmPFvjDgVuJNCLGh6WGKwCkf56uj,T00000LTD37o7rLoPFcgpHWjDQxESSxrGvaNrpGt,T00000LL9s2YtuNUcAoUUrnxcSXBd4W6wSdzjemf,T00000LMzNdxFwAxmd2ZVBreLK2vSS49WzCJVoVG,T00000LMvBMjfoqDQC73oSWo5sD67P5xjk9fQaCe,T00000Lbip8pqD91fVpJHLzyVZAQiQCsmbxyEs6y,T00000LYkwwpkJop7HEMVuqbsDZr4RaHjrF1wssP,T00000LPBpGtTM45MNdfAiTjugfRCiS7WtaqVcm1,T00000LgdJEmsZD8obxJCXUHpy3ZcGhtDbwCRH2h,T00000LhHZFAXAch4J43H62GKbXDNfrW34mDb8m9,T00000LQu5vJcL6EGZy2ZzZusUFrtySYYndSZkw3,T00000LT1KJ2acbULwtY8oYSTHFxayDAF7dzLv4V,T00000Lc8DpPBmVciGm74DLUM9gFhEZwBFZu5ddf,T00000LMhzYYjuDKxbgb1etKQd57CP8xcbyb7RG9,T00000LSkemDwk8kFWmXLoasgX6C3ffGRxVPjDLf,T00000LhLwuX3Z5BgKpxQZx6c8dAgJXMKF6CTBst,T00000LWY6p1GfHJQ65NyiXGnEtc51i71ujuGDJQ,T00000LMnPbhyrVSjuZPTibWGWK112sCor6aVcvm,T00000LYE6tEd3hiDuS1r2qdv8TTM1n6pPh8gNqp,T00000Lca54DkBgCy4KGnaNCpwsPEeWKAtCd4ZXH,T00000LZyVYYEM5DZd6sBDpdrLhoEzGgUGEGWFK3,T00000LgeZE4QqTGB3932gVH1mmpAwF27zyv7zDz,T00000LhmH4c2difu4BqTUag9bb4adAPPPMUZU55,T00000LSSiNCEtthd2ZPYSfoXRc8cC1dQh8hTFpm,T00000LWCo6FDr2w7fai9LdvQRAyDhratqubngX6,T00000LT1fiim7qkMnQE3aSFMcJPAjJWNzdCh3bx,T00000LT6H8Cuxr1g5vR3sjHDSEim2hds6PL6kSU,T00000LRW3SKquMLh1vPardd7t13xQzQdUKebqrY,T00000LbcZK2pLDDkdfYUciSkSSkSo8hKsJHzVhv,T00000LMUmS4evMZvVxGCM9kwiaZdbHzY6cv8ccx,T00000Lek4eDGNa5Xgnfj1tPaAnBZBX6AiCwFJFf,T00000LMMzgZNF1P9bBQsxbmPsvj6SnD3M2SkFNo,T00000LQH62BkqCYpu5TBd2DqTLh8j438gdfT4E1,T00000LWuAfQogkTN8tyuKJRoHBDtsmaZaqVhXrS,T00000LUXX3qFKX4bn6fvzGmGnY9usnz8JDUd4Pd,T00000LTVQ6xVhK9o1M5sqJ4AYmjMNjSGWF4f4py",
		"max_archive_group_size": "512",
		"validator_reward_ratio": "60",
		"governance_reward_ratio": "4",
		"auditor_reward_ratio": "10",
		"max_gas_contract": "50000000",
		"max_vote_nodes_num": "10000",
		"beacon_tx_fee": "100000000",
		"min_auditor_deposit": "1000000000000",
		"punish_interval_time_block": "8640",
		"zec_election_interval": "259183",
		"workload_per_tableblock": "2",
		"punish_interval_table_block": "368640",
		"sign_block_ranking_reward_threshold_value": "0",
		"max_edge_group_size": "512",
		"min_mainnet_active_votes": "0",
		"min_mainnet_active_validators": "20",
		"total_gas_shard": "2160000000000",
		"cluster_election_interval": "360",
		"min_mainnet_active_auditors": "20",
		"custom_property_name_max_len": "16",
		"min_voter_dividend": "0",
		"min_election_committee_size": "20",
		"initial_total_locked_token": "1000000000000000",
		"rec_standby_pool_update_interval": "11",
		"min_credit": "100000",
		"usedgas_decay_cycle": "8640",
		"cluster_election_minimum_rotation_ratio": "66",
		"sign_block_ranking_publishment_threshold_value": "10",
		"vote_reward_ratio": "20",
		"award_auditor_credit": "10000",
		"reward_issue_interval": "4297",
		"tx_deposit_gas_exchange_ratio": "20",
		"tx_send_timestamp_tolerance": "300",
		"application_contract_code_max_len": "32768",
		"cross_reading_rec_standby_pool_contract_height_step_limitation": "12",
		"archive_election_interval": "360",
		"max_auditor_rotation_count": "2",
		"fullunit_contain_of_unit_num": "21",
		"min_node_reward": "0",
		"backward_validator_slash_credit": "100000",
		"cpu_gas_exchange_ratio": "40",
		"min_validator_deposit": "500000000000",
		"max_nodedeposit_lock_duration": "3110400",
		"max_election_committee_size": "20",
		"min_auditor_group_size": "4",
		"edge_reward_ratio": "2",
		"max_gas_account": "1000000",
		"min_mainnet_active_archives": "1",
		"additional_issue_year_ratio": "8",
		"sign_block_publishment_threshold_value": "0",
		"sign_block_reward_threshold_value": "80",
		"min_mainnet_active_edges": "1",
		"backward_auditor_slash_credit": "100000",
		"max_auditor_group_size": "7",
		"min_stake_votes_num": "1",
		"free_gas": "25000",
		"max_validator_group_size": "7",
		"min_ratio_annual_total_reward": "2",
		"min_edge_deposit": "200000000000",
		"custom_property_max_number": "128",
		"workload_per_tx": "1",
		"min_votes_num": "1",
		"zec_standby_pool_update_interval": "31",
		"min_validator_group_size": "4",
		"award_validator_credit": "10000",
		"cross_reading_rec_standby_pool_contract_logic_timeout_limitation": "67",
		"dividend_ratio_change_interval": "120960"
	},
	"sequence_id": "5193415160597868506",
	"errmsg": "OK"
}

# 获取 Unit Block

  • 获取最新高度的Unit Block。

请求方法

topj.getLastUnitBlock

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。
address - String 账户地址。
  • 获取指定高度的Unit Block。

请求方法

topj.getUnitBlockByHeight

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。
address - String 账户地址。
height - Integer 区块高度。

返回参数

参数名称 类型 说明
value Object -
body Object -
lightunit Object 包括 lightunit_input、lightunit_state 两部分。
txs Object 本区块打包的交易信息,结构为 map 数组,map 的 key 为交易 hash,比如 6e734fed40b907bb64d257968e6a46a79c4ca144088d330b674cc8b545350324
tx_consensus_phase Uint8 交易共识阶段:1--self;2--send;3--recv。
enum_transaction_subtype_self = 1, // self operate
enum_transaction_subtype_send = 2, // send to other account
enum_transaction_subtype_recv = 3, // receive from other account
enum_transaction_subtype_recv_ack = 4(confirm), // receive ack from other account
tx_hash string 交易 Hash。
hash String 本块 hash 的十六进制字符串。
header Object -
auditor String 出块的 leader。
auditor_xip String 本块的 auditor leader 节点(xip 格式)。
timerblock_height Uint64 时钟块高度。
validator_xip String 本块的 validator leader 节点(xip格式)。
version String 块版本。
height Uint64 块高度。
owner String unit block 所属账户地址。
prev_hash String 前一区块 hash 的十六进制。
table_height Uint64 table 块高度。
timestamp Uint64 出块时间戳。

账户原生属性说明

属性代码字段 名称 类型 说明
XPROPERTY_CONTRACT_CODE "@1" String 合约执行的具体代码。
XPROPERTY_LOCK_TOKEN_KEY "@4" Map 账号下交易锁定的TOP token集合。
XPROPERTY_LOCK_TOKEN_SUM_KEY "@5" String 锁定的TOP token总数。
XPORPERTY_SUB_ACCOUNT_KEY "@13" Llist 子账号的列表。
XPORPERTY_CONTRACT_SUB_ACCOUNT_KEY "@14" List 合约子账号列表。
XPORPERTY_CONTRACT_PARENT_ACCOUNT_KEY "@15" String 合约父账号。
XPROPERTY_USED_TGAS_KEY "@30" String gas衰减值。
XPROPERTY_LAST_TX_HOUR_KEY "@32" String 最近一次更新@30的逻辑时钟。
XPROPERTY_USED_DISK_KEY "@34" String 使用的disk,本期暂时无用。
XPROPERTY_CONTRACT_TGAS_LIMIT_KEY "@37" String 合约的tgas_limit,合约为调用自己支付的gas上限。
XPROPERTY_PLEDGE_VOTE_KEY "@45" List 用于兑换选票、解锁兑换选票锁定金,存储账户所有兑票交易。
XPROPERTY_EXPIRE_VOTE_TOKEN_KEY "@46" String 兑换选票中,所有锁定期到期的TOP token值。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.block.UnitBlockResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetLastUnitBlock {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");

        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<UnitBlockResponse> sb = topj.getLastUnitBlock(account, account.getAddress());
        String s = JSON.toJSONString(sb.getData());
        System.out.println(s);
    }
}

返回样例

{
  "value":{
    "body":{
      "lightunit":{
        "txs":[
          {
            "tx_consensus_phase":"send",
            "tx_hash":"0xebcaad282eb7c03886372b26493b3d075ee0ae239839753efff9b0b8317c0656"
          }]
      }
    },
    "hash":"3ba75a0a15b97acfe99e787332e771380fd7cc6f9be5325f8a0173edf3ae68cc",
    "header":{
      "auditor":"T00000LPXfPyqcCrzgVyKZEhqcKtLp5yGDiRxHSL",
      "auditor_xip":"1c000000000007b:f60000ff00040404",
      "timerblock_height":7707862,
      "validator_xip":"1c000000000007b:f60000ff000503ff",
      "version":"196608"
    },
    "height":128,
    "owner":"T00000LSygN1JSvh6U1TuAH9FZa26rdfmTajcxtX",
    "prev_hash":"452efe0114610b5cb85a4cb99f365a4ead3ee802d7162312a42f7bb00c177261",
    "table_height":465,
    "timestamp":1650267820
  }
}

# 获取 Table Block

  • 获取最新高度的table block。

请求方法

topj.getLastTableBlock

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象
address - String 账户地址
  • 获取指定高度的table block。

请求方法

topj.getTableBlockByHeight

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象
address - String 账户地址
height - Integer 区块高度

返回参数

参数名称 类型 说明
data Object -
value Object -
body Object -
tableblock Object table block 下包含多个 units,当链上长时间没有新交易,查询tableblock 最新高度数据为"null"。
units Object tableblock 存储若干 unit 块相关信息。
account String 账户地址。
unit_height Uint64 unit block 高度。
hash String 块 hash 的十六进制字符串。
header Object -
auditor String 出块的 leader。
auditor_xip String 本块的 auditor leader 节点(xip 格式)。
multisign_auditor string 出块节点,multisign_auditormultisign_validator 二者不能同时为空。
multisign_validator string 负责打包出块的节点。
timerblock_height Uint64 时钟块高度。
validator_xip String 本块的 validator leader 节点(xip 格式)。
version String 块版本。
height Uint64 块高度。
owner String table block所属账户地址。
prev_hash String 前一区块hash的十六进制。
table_height Uint64 table 块高度,和 height 一致 。
timestamp Uint64 出块时间戳。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.block.TableBlockResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;

public class GetLastTableBlock {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");

        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<TableBlockResponse> sb = topj.getLastTableBlock(account, account.getAddress());
        String s = JSON.toJSONString(sb);
        System.out.println(s);
    }
}

返回样例

{
  "data":{
    "value":{
      "body":{
        "tableblock":{
          "txs":[
            {
              "tx_consensus_phase":"send",
              "tx_hash":"0x4a334051b7a199af5694e9c5e2cbf6d1190de95148a9cf9ca0e9abf05b6857fb"
            }],
          "units":[
            {
              "account":"T00000LWxPzhvHkPifdEAHQnWijWkiVUtqzFdnZQ",
              "unit_height":4
            }]
        }
      },
      "hash":"a38b1f121383c56455eb0968aa2834e70e926f01d2ada5e1d1da3b2132f9c335",
      "header":{
        "auditor":"T00000LWi3nfReoWFHsXerSqhn7gCFLFW8L4YB71",
        "auditor_xip":"100000000000001:f60000ff00040401",
        "multisign_auditor":"740000005800000031f768bd00000000210003f5c142ecc0dc43e23ccbc30e4ac3b9c44a9dffe8fb619bc667a1b9b36668fc492000c426714873a81a28a8394d7fb111292879f60e262231f7943b565385a3ca5ef304000e",
        "multisign_validator":"740000005800000031f768bd00000000210003447276b3f8a80fcc098ca7c2751432b8b14b453647d66e905af1acaae5f028a720000ef592d465d52fd39c5d2c65b1e59c39e5432a68c033f0bd21fae7265d6dbef604000d",
        "timerblock_height":7684597,
        "validator_xip":"100000000000001:f60000ff000507ff",
        "version":"196608"
      },
      "height":46,
      "owner":"Ta0000@29",
      "prev_hash":"df46abed91fa9747142826f506921082fd10e59c09ab922d6dd03e4f4a69c2a5",
      "table_height":46,
      "timestamp":1650035170
    }
  },
  "errmsg":"OK",
  "errno":0,
  "sequence_id":"880646877990206582"
}

# 账户管理

# 查询链上账户信息

当一个用户发送交易至链上时,必须要使用该用户最新的"nonce"和"last_hash_xxhash64",这两个属性可以从该方法的返回值中获取。

请求方法

topj.getAccount

请求参数

参数名称 是否必选 默认值 类型 说明
account - Account 账户对象。

返回参数

参数名称 类型 说明
account_addr String 账户地址。
available_gas Uint64 账户现有可用gas的量,单位Tgas。如返回值为负,可能因为两种原因:1.获取了免费gas后账户余额不足100*10^6 uTOP;2.在用完锁定TOP token兑换的gas后解锁TOP token。
balance Uint64 账户余额,单位uTOP。
burned_token Uint64 该账户所有已经销毁的TOP token,单位uTOP。
cluster_id Uint8 cluster ID。
created_time Uint64 账户在链上创建的时钟高度。
disk_staked_token Uint64 兑换disk锁定的TOP token,单位uTOP。
gas_staked_token Uint64 兑换gas锁定的TOP token,单位uTOP。
group_id Uint8 group ID。
latest_tx_hash String 最新共识成功的交易hash。
latest_tx_hash_xxhash64 String 最新共识成功的交易xx64hash。
latest_unit_height Uint64 最新共识成功的交易的unit block高度。
lock_balance Uint64 锁定的TOP token,单位uTOP,主要用于用户合约交易。 调用用户合约的时候,交易发送方可同时给合约账户转账,如果合约执行失败,转账款需要退还给发送方,所以在合约执行成功前,先将转账款锁定。
lock_gas Uint64 用户合约交易费用与据执行合约交易占用的CPU时长以及交易大小相关,无法在交易开始确定合约的交易费用。采取的方法是冻结发送方一部分gas,在交易第三次共识的时候,根据合约的最终执行情况,扣除发送方交易消耗的gas,单位Tgas。
nonce Uint64 该账户最新共识成功的交易序号,唯一。
total_free_gas Uint64 账户免费获取的gas总量,单位Tgas。目前当账户余额≥100*10^6 uTOP,系统会免费赠与该账户25,000 Tgas。该值随着链上参数治理变化而变化。
total_gas Uint64 账户gas总量,单位Tgas。 一个普通账户24小时内可以获得的gas不超过200,000Tgas。 一个合约账户24小时内可以获得的gas不超过10,000,000Tgas。
total_stake_gas Uint64 账户锁定TOP token而获得的gas总量,单位Tgas。
unlock_disk_staked Uint64 解锁中的兑换disk的TOP token,发起解锁后,需要等待24小时,并由锁定账户发起一笔交易后,解锁的金额才会到账。
unlock_gas_staked Uint64 解锁中的兑换gas的TOP token,发起解锁后,需要等待24小时,并由锁定账户发起一笔交易后,解锁的金额才会到账。
unused_free_gas Uint64 免费gas余量,单位Tgas。
unused_stake_gas Uint64 锁定TOP token兑换的gas余量,单位Tgas。
unused_vote_amount Uint64 该账户未使用选票数量。
vote_staked_token Uint64 兑换选票锁定的TOP token,单位uTOP。
zone_id Uint8 zone ID。
tableid Unit16 Table 的 ID。
recv_tx_num Uint64 账户作为接收方的交易数量。

账户所属分片网络信息:

ID 分片网络
zone_id、cluster_id、group_id,分别为1、0、0或者2、0、0 Beacon Network
zone_id、cluster_id、group_id,分别为14、1、1 Archive Network
zone_id、cluster_id、group_id,分别为15、1、1 Edge Network
zone_id、cluster_id,分别为0、1,group_id的值为[1,63] Audit Network
zone_id、cluster_id,分别为0、1,group_id的值为[64,126] Validate Network

如查询用户合约账户信息,以上参数除"contract_address"外,新增以下两个参数。

参数名称 类型 说明
contract_code String 合约代码。
contract_parent_account String 合约父账户,部署合约的账户。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.AccountInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetAccount {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        ResponseBase<AccountInfoResponse> accountInfoResponse = topj.getAccount(account);
        System.out.println(JSONObject.toJSON(accountInfoResponse));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"total_gas": 25138,
		"account_addr": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
		"unused_stake_gas": 138,
		"unlock_disk_staked": 0,
		"available_gas": 24390,
		"total_free_gas": 25000,
		"table_id": 3,
		"total_stake_gas": 138,
		"zone_id": 0,
		"cluster_id": 1,
		"balance": 199978600,
		"latest_unit_height": 10,
		"unlock_gas_staked": 4000,
		"gas_staked_token": 16000,
		"created_time": 1642066250,
		"disk_staked_token": 0,
		"unused_vote_amount": 0,
		"unused_free_gas": 24252,
		"nonce": 8,
		"latest_tx_hash": "0xab24e8aa4f93f0d2d450360c0ef11614998c275ccf1d32d39a5a22cc6f57db38",
		"burned_token": 0,
		"latest_tx_hash_xxhash64": "0xa5bfa37aa1edd3f5",
		"vote_staked_token": 0,
		"group_id": 64,
		"recv_tx_num": 2,
		"lock_balance": 4000
	},
	"sequence_id": "4533788721199354927",
	"errmsg": "OK"
}

# 转账

将 TOP 转到另外一个账户地址。

请求方法

topj.transfer

请求参数

参数名称 是否必填 默认值 类型 说明
account - Object 发送交易前,需要先获取最新的nonce和last_hash_xxhash64,赋值于需要使用的account对象中,可直接调用"topjs.updateNonceAndLastHash"方法,将自动把这两个参数放入account对象中。
to - String 交易接收账户地址,为普通账户或者合约账户。
接收者地址在"target_action"对象下的"account_addr"属性中。
note 空字符串 String 转账备注。
amount - Uint64 转账金额,单位uTOP。

返回参数

返回交易结果对象,请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;
import java.math.BigInteger;

public class Transfer {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.transfer(account,"T80000bde88ffafff06e99f77b9c1e3db3f0d903597f93", BigInteger.valueOf(1400), "转账");
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@22",
				"height": 31
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 207
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 426,
				"account": "Ta0000@44",
				"height": 204
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "转账",
			"receiver_account": "T80000bde88ffafff06e99f77b9c1e3db3f0d903597f93",
			"premium_price": 0,
			"authorization": "0x007f584d661de5fd3973c0f461da3ddc8685c97d797788d7c1ec686cd39306e2a52d9e95ac469166e8e7890867b0e38138a165bcfd069d5bd7de1ce56b71779572",
			"from_ledger_id": 0,
			"send_timestamp": 1642228667,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 4,
			"ext": "",
			"amount": 1400,
			"tx_len": 142,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x21c05535fd63dc3f6fab717b61cb0bb8146daad8b8d57927e3c5d397d564916b",
			"last_tx_nonce": 24,
			"sender_action_param": "0x03000000544f507805000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x03000000544f507805000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 142,
	"sequence_id": "-7650297722120497985",
	"errmsg": "OK",
	"tx_hash": "0x21c05535fd63dc3f6fab717b61cb0bb8146daad8b8d57927e3c5d397d564916b"
}

# 查询账户交易详情

请求方法

topj.getTransaction

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
txHash - String 交易hash。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetTransaction {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.getTransaction(account,"0xf6deeb9c5e46b379bae112a83bb9e4f3bdc14c63031e4ed7bdfa27f5dd0f7dff");
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

根据交易不同状态,返回交易信息不同,具体如下。

交易为单账户交易,交易只在交易发送方下进行一次共识,查询交易最终返回结果中只有"confirm_block_info"的信息。

交易为跨账户交易,交易总共需要进行三次共识,查询交易最终返回结果中包括三次共识的信息,包括"confirm_block_info(发送方第二次共识)"、"recv_block_info(接收方共识)"、"send_block_info"(发送方第一次共识),如下所示。

  1. 交易在区块中,但不在交易池中,交易状态为"confirmed",返回交易原始信息及所有区块信息,如下所示。

    根据返回参数exec_status判断交易最终是否成功:

    • 当exec_status返回值为"success",证明交易最终成功。

    • 当exec_status返回值为"failure",则交易失败,此时recv_tx_exec_status返回值为"failure",表明交易接收方共识失败。

      {
      "errno":0,
      "data":{
          "tx_consensus_state":{
          "recv_block_info":{
              "used_gas":0,
              "account":"Ta0000@5",
              "height":165310
          },
          "confirm_block_info":{
              "used_deposit":0,
              "exec_status":"success",
              "recv_tx_exec_status":"success",
              "used_gas":0,
              "account":"Ta0000@4",
              "height":482333
          },
          "send_block_info":{
              "tx_fee":0,
              "used_deposit": 0,
              "used_gas":558,
              "account":"Ta0000@4",
              "height":482333
          }
          },
          "failure":false,
          "success":true,
          "original_tx_info":{
          "note":"subscription",
          "receiver_account":"T00000LRHtK4YRD7z8VJLW9s9mSw2sbxKUsyMjeP",
          "premium_price":0,
          "authorization":"0x0180cc4b53871be19ff816a4be82a62f8e29d34d53ecbaccf6eb2c7720286a5fc85db1229ff679330c5c729f3cee6ba43139423c5a14459810bdca4e5c5000d366",
          "from_ledger_id":0,
          "send_timestamp":1650972889,
          "token_name":"",
          "tx_random_nonce":0,
          "tx_type":4,
          "ext":"",
          "amount":1,
          "tx_len":186,
          "edge_nodeid":"",
          "tx_structure_version":2,
          "tx_hash":"0xb60a510ad25d95e39d29333f235dc8c097d15cdd96a381611df2ba35c61da1e9",
          "last_tx_nonce":5177,
          "sender_action_param":"{\"amount\":1,\"token_name\":\"TOP\"}",
          "last_tx_hash":"",
          "tx_deposit":100000,
          "sender_action_name":"",
          "tx_expire_duration":100,
          "receiver_action_param":"{\"amount\":1,\"token_name\":\"TOP\"}",
          "sender_account":"T00000LTc1yaVCqMH5g3DNKG9i3px13KmsJBbMkb",
          "to_ledger_id":0,
          "challenge_proof":"",
          "receiver_action_name":""
          }
        },
      "sequence_id":"5817967982351345580",
      "errmsg":"OK"
      }
      
  2. 交易同时在区块和交易池中,交易状态为"queue",此时查询交易返回交易原始信息,及部分有效区块信息。

    如下所示,此时交易完成了第一轮共识,返回"send_unit_info"有效信息,而此时第二、三轮共识尚未成功。

    {
    'original_tx_info': {
        'amount': 100,
        'authorization': '0x0000d616b2dc5f89af842910d59ce214f6341daf60068a87b387a9274f734b30e81d24f258189d4f52e7789d239065f021d3abaab23f2739e0a71001ac9c7b8b37',
        'edge_nodeid': '',
        'ext': '',
        'last_tx_nonce': 1,
        'note': 'test_app',
        'premium_price': 0,
        'receiver_account': 'T80000b871687e28e8d123937b80cb3fd19e72ff02729d',
        'receiver_action_name': '',
        'receiver_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'send_timestamp': 1651037348,
        'sender_account': 'T80000baf4619bd40a8ff7795170392d7a608069665a42',
        'sender_action_name': '',
        'sender_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'token_name': '',
        'tx_deposit': 100000,
        'tx_expire_duration': 100,
        'tx_hash': '0x60006ee3838a221463e40f45941053a3276a65417b4b88ba68337bb95c83934a',
        'tx_len': 143,
        'tx_structure_version': 2,
        'tx_type': 4
    },
    'tx_consensus_state': {
        'recv_block_info': {
        'height': None
        },
        'send_block_info': {
        'account': 'Ta0000@6',
        'height': 4,
        'tx_fee': 0,
        'used_deposit': 0,
        'used_gas': 429
        }
    },
    'tx_state': 'queue'
    }
    
  3. 交易不在区块,在交易池中,交易状态为"pending",只返回交易原始信息,交易共识信息为"null",如下所示。

    {
    'original_tx_info': {
        'amount': 100,
        'authorization': '0x0000d616b2dc5f89af842910d59ce214f6341daf60068a87b387a9274f734b30e81d24f258189d4f52e7789d239065f021d3abaab23f2739e0a71001ac9c7b8b37',
        'edge_nodeid': '',
        'ext': '',
        'last_tx_nonce': 1,
        'note': 'test_app',
        'premium_price': 0,
        'receiver_account': 'T80000b871687e28e8d123937b80cb3fd19e72ff02729d',
        'receiver_action_name': '',
        'receiver_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'send_timestamp': 1651037348,
        'sender_account': 'T80000baf4619bd40a8ff7795170392d7a608069665a42',
        'sender_action_name': '',
        'sender_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'token_name': '',
        'tx_deposit': 100000,
        'tx_expire_duration': 100,
        'tx_hash': '0x60006ee3838a221463e40f45941053a3276a65417b4b88ba68337bb95c83934a',
        'tx_len': 143,
        'tx_structure_version': 2,
        'tx_type': 4
    },
    'tx_consensus_state': null,
    'tx_state': 'pending'
    }
    

# 锁定token兑换gas

兑换gas的价格为:

兑换gas的价格

此兑换率随着系统中锁定的TOP tokens变化而变化。

一个普通账户24小时内可以获得的gas不超过200,000Tgas,大约可以发起800条交易。

一个合约账户24小时内可以获得的gas不超过10,000,000Tgas,大约可以执行4万条交易,使用4秒CPU。

账户24小时内最多可兑换的gas=24小时内可以获得的gas上限-24小时内免费gas。

请求方法

topj.stakeGas

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
locked_utop - Uint64 锁定金额,单位uTOP。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeGas {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeGas(account, BigInteger.valueOf(4000));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 151,
				"account": "Ta0000@3",
				"height": 58
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"premium_price": 0,
			"authorization": "0x0180fdea4bfdcf1dc7b7001fa3b632fc8adfe126e9bd9375ee343d904cc560fee53eeba47ba7f61fc7d34c40bc677e31635530dbd4618d25299c33bd1acdf545b6",
			"from_ledger_id": 0,
			"send_timestamp": 1642228333,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 22,
			"ext": "",
			"amount": 0,
			"tx_len": 151,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x8ff271442ed894a8f57cc6642ed8469584bf962252ddd32ada780c4cdc6ad4ea",
			"last_tx_nonce": 8,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000a00f000000000000",
			"sender_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 151,
	"sequence_id": "5460731776410679387",
	"errmsg": "OK",
	"tx_hash": "0x8ff271442ed894a8f57cc6642ed8469584bf962252ddd32ada780c4cdc6ad4ea"
}

# 解锁兑换gas的token

发起解锁后,需要等待24小时,并由锁定账户发起一笔交易后,解锁的金额才会到账。

请求方法

topj.unStakeGas

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
unlocked_utop - Uint64 解锁金额,单位uTOP。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;
import java.math.BigInteger;

public class UnStakeGas {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeGas(account, BigInteger.valueOf(2000));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 151,
				"account": "Ta0000@3",
				"height": 61
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"premium_price": 0,
			"authorization": "0x01dcd27457c0bafa4ea83a8b3aa3aaa66e5559a0fe5bf522673e22c889ecf990156dc05ff6473120dd19f7e501e1510d5f69923d7a134b1b5a92183b16c5cd0d31",
			"from_ledger_id": 0,
			"send_timestamp": 1642229760,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 23,
			"ext": "",
			"amount": 0,
			"tx_len": 151,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x97960b275c567ac65b8fad16d36da7378c333be92603eecc3ec86daa348aad02",
			"last_tx_nonce": 9,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000d007000000000000",
			"sender_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 151,
	"sequence_id": "7557049805931304829",
	"errmsg": "OK",
	"tx_hash": "0x97960b275c567ac65b8fad16d36da7378c333be92603eecc3ec86daa348aad02"
}

# 矿工操作

# 注册矿工

TOP AI Network 目前有五种类型的矿工:边缘矿工(edge)、验证矿工(validator)、高级矿工(advance)、存档矿工(archive)和交易所矿工(exchange)。您可以注册成为前三种矿工类型的其中一种。

高级矿工可在不同的网络里同时担任多个节点:验证节点(validator)、审计节点(auditor)。

以下是各类型矿工注册的最低保证金要求。

矿工类型 最低注册保证金
边缘矿工(edge) 100,000*10^6 uTOP token
验证矿工(validator) 500,000*10^6 uTOP token
高级矿工(advance) 1,000,000*10^6 uTOP token

请求方法

topj.registerNode

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
mortgage - Uint64 注册保证金,单位uTOP。
nodeType - String 矿工类型,包括 edge(边缘矿工)、validator(验证矿工)、advance(高级矿工)、archive(存档矿工)和 exchange(交易所矿工)。
您可以注册成为前三种矿工类型的其中一种。
注册成为高级矿工后,advance矿工被选举为何种节点取决于矿工的选票:
advance矿工被选举为auditor节点,矿工所获得的选票需要大于等于节点实际质押的保证金(此处矿工保证金以TOP计算,非uTOP)。
当选票低于实际质押保证金时,advance矿工只能被选为validator。
说明:
矿工选票须由接受投票而得,可以由其他矿工投票,也可由本账户投票。
nickName - String 矿工昵称,4-16字符,字母、数字或下划线。
node_sign_key - String owner key或者worker key的公钥。将此公钥信息登记到区块链系统注册合约中,其他节点可使用此公钥对矿工发送的交易验签。为了保护您的账户安全,建议您将owner key和worker key分离使用,离线保存owner key。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.property.NodeType;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class RegisterNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        account.setAddress("T800005cb91f65f64f6247852a1419307a940ff507e362");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.registerNode(account, BigInteger.valueOf(1100000000000L), NodeType.advance, "topNode1", "238a2d2f4aae4b397d6604db54b6bb765e18a93e5f775d213e031383d9830142e078c088dd296f78d7dbdf43077dec6ca07e34c6d9fa5b4f1acf7773a237ea42", BigInteger.valueOf(20));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 216
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@8",
				"height": 103
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 1041,
				"account": "Ta0000@8",
				"height": 100
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x007743882dd2534e5d1c77873fee8281e84c7d9a78c688cd856989f219ce0cdb2b65ccb4156532f17f1a4407d35007a7d89e91fc991f2d4c420546cdc20359ee23",
			"from_ledger_id": 0,
			"send_timestamp": 1642406785,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 347,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x6b05f662add51d47ccff885085d03ffb6d3b117d8d9604740eb92ea0eb233a6d",
			"last_tx_nonce": 0,
			"sender_action_param": "0x0000000000f81b1d00010000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x07000000616476616e636508000000746f704e6f646531800000003233386132643266346161653462333937643636303464623534623662623736356531386139336535663737356432313365303331333833643938333031343265303738633038386464323936663738643764626466343330373764656336636130376533346336643966613562346631616366373737336132333765613432020000003230",
			"sender_account": "T800004ffdd1cec893a4d79eb2e97656378348618c847f",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "registerNode"
		}
	},
	"tx_size": 347,
	"sequence_id": "2835273932371462638",
	"errmsg": "OK",
	"tx_hash": "0x6b05f662add51d47ccff885085d03ffb6d3b117d8d9604740eb92ea0eb233a6d"
}

# 查询矿工信息

请求方法

topj.queryNodeInfo

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
nodeAddress - String 矿工账户地址。

返回参数

参数名称 类型 说明
account_addr String 矿工账户地址。
auditor_credit String auditor节点信誉分。
auditor_stake Uint64 uditor节点权益:auditor stake=(矿工保证金+矿工得票总数/2)*信誉分
dividend_ratio Integer 分红率,百分比%,值为[0,100]。
network_id String 节点经过选举后,加入的具体的网络ID。
node_deposit Uint64 矿工注册保证金,单位uTOP。
nodename String 矿工昵称。
registered_node_type String 矿工注册类型:
边缘矿工:edge
验证矿工:validator
高级矿工:advance
node_sign_key String 注册矿工时使用的公钥。
validator_credit String validator节点信誉分。
validator_stake Uint64 validator节点权益:validator stake=sqrt[(矿工保证金+矿工得票总数/2)*validator信誉分]
vote_amount Uint64 矿工得票总数。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.NodeInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryNodeInfo {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<NodeInfoResponse> nodeInfo = topj.queryNodeInfo(account, account.getAddress());
        System.out.println("node info > " + JSON.toJSONString(nodeInfo));
    }
}

返回样例

{
	"data": {
		"account_addr": "T800005cb91f65f64f6247852a1419307a940ff507e362",
		"auditor_credit": "0.330000",
		"auditor_stake": 166155033,
		"dividend_ratio": 2,
		"network_id": "255 ",
		"node_deposit": 3500000005000,
		"node_sign_key": "9bd05405d9c6363e5b1c70717623ae3f2c0a43b5d77d1a1310fdc54d205e614712cd89c6cf876453cee783af6a3c2b9c4b1632ce35f7b405de185ea5773e37c5",
		"nodename": "topNode1",
		"rec_stake": 503500100,
		"registered_node_type": "advance",
		"validator_credit": "0.330000",
		"validator_stake": 5000,
		"vote_amount": 1000000200,
		"zec_stake": 503500100
	},
	"errmsg": "OK",
	"errno": 0,
	"sequence_id": "7304676093041685078"
}

# 更新矿工类型

请求方法

topj.updateNodeType

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
mortgage - BigInteger 矿工保证金。
nodeType - String 矿工类型,所有类型都在NodeType对象下。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.property.NodeType;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UpdateNodeType {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.updateNodeType(account, BigInteger.valueOf(1200000000000L), NodeType.advance);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 195
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 232
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 597,
				"account": "Ta0000@44",
				"height": 229
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x006707d83a7c5068468bf6abd3f2d2cc742cd02a86feb1e5e5663d39a218189ce409c3fedaa48b5b9d1a534a10a2a5e6cc7c07825ed6a8988c4730a5d965fd3dfd",
			"from_ledger_id": 0,
			"send_timestamp": 1642230017,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 199,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x8e166f73dae9d71898039f4ebb2a1fa5a74b50108f069be58794878afa018873",
			"last_tx_nonce": 27,
			"sender_action_param": "0x0000000000e092651701000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x0400000065646765",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "updateNodeType"
		}
	},
	"tx_size": 199,
	"sequence_id": "-2105626912941656979",
	"errmsg": "OK",
	"tx_hash": "0x8e166f73dae9d71898039f4ebb2a1fa5a74b50108f069be58794878afa018873"
}

# 设置矿工昵称

请求方法

topj.setNodeName

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
nickname - String 矿工昵称

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class SetNodeName {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.setNodeName(account, "nick2");
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 285
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 437
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 579,
				"account": "Ta0000@44",
				"height": 434
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x00c3cbbd11a126a781cf4049405f0c8fc585e2ad5c42c9fc3dd34abada260369e80b8ae1bac77fbc562d4b2eac2fc7cf57dca0feea2ef812a6c16ccdaaf924c4c0",
			"from_ledger_id": 0,
			"send_timestamp": 1642564755,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 193,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x966466ad79770ad50f6686b1273a59d77cd50ba795b241e2001478eb8ee20d9e",
			"last_tx_nonce": 46,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x050000006e69636b32",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "setNodeName"
		}
	},
	"tx_size": 193,
	"sequence_id": "-7844052753189848288",
	"errmsg": "OK",
	"tx_hash": "0x966466ad79770ad50f6686b1273a59d77cd50ba795b241e2001478eb8ee20d9e"
}

# 增加矿工保证金

您可以随时为矿工增加保证金,从而提高您节点的综合权益(Comprehensive Stake)。

增加矿工保证金不会改变您注册的矿工类型。

请求方法

topj.stakeDeposit

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
mortgage - BigInteger 抵押金

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeDeposit(account, BigInteger.valueOf(5000));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 186
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 198
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 555,
				"account": "Ta0000@44",
				"height": 195
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x0088f7daebe286140811b55ec7c3dedbbcef9be0ee9a38d6a1281c4793e0517d2e1b365abeaa991dbf92c4849df6c462bbecd2a51a79796be29c114e7349146bde",
			"from_ledger_id": 0,
			"send_timestamp": 1642228256,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 185,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xb3f1f19fcde745cfa902e4f6619f01b07aea8120b36ad1732959547ecc420f6b",
			"last_tx_nonce": 22,
			"sender_action_param": "0x000000008813000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "stakeDeposit"
		}
	},
	"tx_size": 185,
	"sequence_id": "6811970780427338832",
	"errmsg": "OK",
	"tx_hash": "0xb3f1f19fcde745cfa902e4f6619f01b07aea8120b36ad1732959547ecc420f6b"
}

# 减少矿工保证金

您可以随时减少质押的保证金,减少保证金不会改变您注册的矿工类型,但是如果质押的保证金低于当前类型矿工注册保证金最低要求,减少保证金将失败。

请求方法

topj.unStakeDeposit

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
mortgage - BigInteger 抵押金

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UnStakeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeDeposit(account, BigInteger.valueOf(3500));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 297
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 456
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 585,
				"account": "Ta0000@44",
				"height": 453
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x0086c83cd67b6ffa979d8f9e454a4876b49278efd2b8bb556d9daf4be8124b6c1717cef41ae49733f8fe2b0569fa4bc8f0eee052375ef5dd1261db7d7d8e8ea4e0",
			"from_ledger_id": 0,
			"send_timestamp": 1642566310,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 195,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x4b70fbcc055f548633ba575ad74cf0b78b67e1e72bcade9b4d9ad1d18cf10e6f",
			"last_tx_nonce": 49,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0xac0d000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unstakeDeposit"
		}
	},
	"tx_size": 195,
	"sequence_id": "-6110982047882771409",
	"errmsg": "OK",
	"tx_hash": "0x4b70fbcc055f548633ba575ad74cf0b78b67e1e72bcade9b4d9ad1d18cf10e6f"
}

# 设置分红比例

如果您注册成为高级矿工,可设置分红比例,您收到的全部奖励(包括但不限于工作量奖励和节点选票奖励),将按照分红比例分到支持您的投票者账户。

请求方法

topj.setDividendRate

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
dividendRate - BigInteger 分红比例 [0 ~ 100]。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class SetDividendRate {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.setDividendRate(account, BigInteger.valueOf(30));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 288
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 443
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 591,
				"account": "Ta0000@44",
				"height": 440
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x00e6f61a751f342ed4c83ee9a5f371de83a11ff68b9c515e9e0f96b6f68fba1faa7af66acdc59502dcbfbdd04bec20642fe82e702265c42f7e93672e5beaf652e6",
			"from_ledger_id": 0,
			"send_timestamp": 1642566017,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 197,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xcad5c6a13236e2150af3512a37a1df55f51e11b6cc268c388b2cfbae1c7d5ce2",
			"last_tx_nonce": 47,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x1e00000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "setDividendRatio"
		}
	},
	"tx_size": 197,
	"sequence_id": "1124612228439604214",
	"errmsg": "OK",
	"tx_hash": "0xcad5c6a13236e2150af3512a37a1df55f51e11b6cc268c388b2cfbae1c7d5ce2"
}

# 查询账户投票分布信息

请求方法

topj.listVoteUsed

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
voterAddress - String 投票者账户地址。

返回参数

参数名称 类型 说明
vote_infos Map数组 接收投票账户地址(String);投票数量(Integer)。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.VoteUsedResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ListVoteUsed {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<VoteUsedResponse> result = topj.listVoteUsed(account, "T00000LWxPzhvHkPifdEAHQnWijWkiVUtqzFdnZQ");
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"vote_infos": {
			"T800005cb91f65f64f6247852a1419307a940ff507e362": 1000000000
		}
	},
	"sequence_id": "-3413557920370207769",
	"errmsg": "OK"
}

# 注销矿工

在TOP AI Network主网的节点要退出主网, 需要先注销矿工。

  • 矿工注销只能矿工主动发起。

  • 矿工注销后, 保证金不会立马退回到矿工账户, 会被锁定72小时。

  • 锁定的保证金到期后需要矿工主动发起赎回保证金的操作,不会自动退回。

请求方法

topj.unRegisterNode

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class UnRegisterNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unRegisterNode(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 303
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 463
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 573,
				"account": "Ta0000@44",
				"height": 460
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x01e6fca2abb2fcfadf4bc8a042bf48e654cb0616fc59d75acd2fcbcd3820083c526486baf27567d39cd01dd812ed75efd6de6802181307a9c96259b1c636497521",
			"from_ledger_id": 0,
			"send_timestamp": 1642566442,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 191,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x41757c28579469b5f18334d6f8ca15a8f1e0e016a85e0fb7a62c2b9e7c1d855e",
			"last_tx_nonce": 50,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unregisterNode"
		}
	},
	"tx_size": 191,
	"sequence_id": "2061817932696966527",
	"errmsg": "OK",
	"tx_hash": "0x41757c28579469b5f18334d6f8ca15a8f1e0e016a85e0fb7a62c2b9e7c1d855e"
}

# 赎回矿工保证金

矿工注销后,矿工保证金将会被锁定72小时,锁定的保证金到期后需要矿工主动赎回保证金,系统不会自动退回。

请求方法

topj.redeemNodeDeposit

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class RedeemNodeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.redeemNodeDeposit(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01ace90aad93209164cc3976520d2393043b88e8ba151c69f4c0ff79caabd586b60cf5887b99db8cf3729e0e6e84d443ae3bc859fad75f44a1200d18e164db8258",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 5154942665457376997,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603783905,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "redeemNodeDeposit",
               "action_param" : "",
               "action_size" : 87,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138DSqqwBWkHKxkVuCq3htW47BGtJRCM2paf@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x22e076b89df6795434e8dc86460b5e6157642a906d83b1eec8d2fac1d522d9fd",
         "tx_len" : 312,
         "tx_random_nonce" : 0,
         "tx_structure_version": 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 10,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "b4d2d5ed1eb7a29a706eafaba69fded704a1b2155757598f9adec45eaa4d043e",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 11,
            "unit_hash" : "b14b2f771b6b8311fb6aa86288dd8069ad729ceccd355aa702c237de170684dc",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 9,
            "tx_fee" : 100000000,
            "unit_hash" : "73f642b73ec9bc7ac27032261d921b04dabb9fb6ab2561baa7ba2a9a928d1db5",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 936
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "51"
}

# staking

# 锁定token兑换选票

兑票规则:

locked TOP token=votes_amount / [ 1.04^(lock_duration / 30 - 1) ], duration < 570;

locked TOP token=vote_amount / 2, lock_duration >= 570。

锁定期越长,相同的兑票数量锁定越少的TOP token。

请求方法

topj.stakeVote

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
amount - Uint64 兑票数量。
lockTime - String TOP token锁定期,锁定期单位:天。
锁定期最少为30天,且必须为30的整数倍。锁定期越长,相同的兑票数量锁定越少的TOP token。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeVote(account, BigInteger.valueOf(11000), BigInteger.valueOf(30));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 149,
				"account": "Ta0000@44",
				"height": 201
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"premium_price": 0,
			"authorization": "0x006f3f00f51f25db0b82b7f312205214cfa93e0cefecd5cfc76b2095fc3a61ceac148e3b8e8e209656f9430ec4c810848fe94745362e3c28e5b74d77dd6d8b2e25",
			"from_ledger_id": 0,
			"send_timestamp": 1642228383,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 27,
			"ext": "",
			"amount": 0,
			"tx_len": 149,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x6b53073a1e02a3ae87060968fb4c68aac3e87fa3d5675953952fe9a4a078c728",
			"last_tx_nonce": 23,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x4c040000000000001e00",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 149,
	"sequence_id": "3931658814308494287",
	"errmsg": "OK",
	"tx_hash": "0x6b53073a1e02a3ae87060968fb4c68aac3e87fa3d5675953952fe9a4a078c728"
}

# 解锁兑换选票的token

锁定期内的TOP token不能解锁,只能解锁到期的TOP token。

已经被使用的选票对应锁定的TOP token不能被解锁。

发起解锁后,解锁的金额会立刻到账。

请求方法

topj.unStakeVote

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
amount - Uint64 选票数量,解锁相应的TOP token。
note - String 备注。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UnStakeVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeVote(account, BigInteger.valueOf(1001));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x00dbb57645b28dc9261bc89c3b403f219c68b00da07d673d5ccb1930f042b8b75e62950579327682a79184e8cb502a5d9639a6d53e5293f52a47842ef965fdd98e",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 7288822057977092395,
         "last_tx_nonce" : 7,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603784708,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "0xce07000000000000",
               "action_size" : 74,
               "action_type" : 22,
               "tx_receiver_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 1,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x6245bed2227b7ff56d5bf6ae239685993f81b65990fe55f2b686e0d189ba50b1",
         "tx_len" : 299,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 28
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 13,
            "tx_exec_status" : "success",
            "unit_hash" : "c192c146d659f023a79eade70b513ec05def9e75a47f3309d7885f2f746fefd2",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 299
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "59"
}

# 投票

投票之前请确保您的账户中有足够的未使用的选票,可使用topj.getAccount查询。如您的账户中没有足够的选票,可通过topj.stakeVote兑换选票。

给高级矿工投票,获取收益:

  • 只有高级矿工才能接受投票;
  • 单个账户目前最多允许给10,000个矿工投票;

  • 给矿工投票后,矿工获取的奖励会有一部分分给投票者。

请求方法

topj.voteNode

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 投票者账户对象。
voteInfo - Map<String, BigInteger> key:矿工账户地址;value:票数。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class VoteNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Map<String, BigInteger> voteInfo = new HashMap<>();
        String nodeAddress = "T800005cb91f65f64f6247852a1419307a940ff507e362";
        voteInfo.put(nodeAddress, BigInteger.valueOf(5000));
        ResponseBase<XTransactionResponse> result = topj.voteNode(account, voteInfo);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 282
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 285
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 684,
				"account": "Ta0000@44",
				"height": 279
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T20000MVfDLsBKVcy1wMp4CoEHWxUeBEAVBL9ZEa@44",
			"premium_price": 0,
			"authorization": "0x00f07f5b4e49f99d84e73ae36124b02b2512f61f6b41b0f9deb251d310c0deffde16273aa8692691ac0c58db56ddc549c89734b8bc976a145b8d7a43f4b5b0bf08",
			"from_ledger_id": 0,
			"send_timestamp": 1642230620,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 20,
			"ext": "",
			"amount": 0,
			"tx_len": 228,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x3ec814a3e0be2da92aec5c885cb629c1ca67daa7a7263e340151b17456f433a0",
			"last_tx_nonce": 33,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x010000002e000000543830303030356362393166363566363466363234373835326131343139333037613934306666353037653336328813000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "voteNode"
		}
	},
	"tx_size": 228,
	"sequence_id": "4242996775985050247",
	"errmsg": "OK",
	"tx_hash": "0x3ec814a3e0be2da92aec5c885cb629c1ca67daa7a7263e340151b17456f433a0"
}

# 取消投票

投票人可以随时将已经投给矿工的选票取消并收回。

每次取消投票的票数无限制,但是不能高于给矿工投票的总数,否则取消投票将失败。

给矿工投票后,即使矿工注销,选票也不会主动退还至您的账户, 取消投票需要您主动发起。

您可以批量取消矿工投票。

请求方法

topj.unVoteNode

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 投票者账户对象。
voteInfo - Map<String, BigInteger> key:矿工账户地址;value:票数。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class UnVoteNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Map<String, BigInteger> voteInfo = new HashMap<>();
        String nodeAddress = "T800005cb91f65f64f6247852a1419307a940ff507e362";
        voteInfo.put(nodeAddress, BigInteger.valueOf(100));
        ResponseBase<XTransactionResponse> result = topj.unVoteNode(account, voteInfo);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 219
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 222
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 690,
				"account": "Ta0000@44",
				"height": 216
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T20000MVfDLsBKVcy1wMp4CoEHWxUeBEAVBL9ZEa@44",
			"premium_price": 0,
			"authorization": "0x00cd2e3414a6bd09a57098b57466dfb19be3be78ed57ab1ba2e0d3374ca194420a0c9c5d7c765e5bc54c32396f1ffb9d7ee4f47e16084fb3780c7fa0f69d64f656",
			"from_ledger_id": 0,
			"send_timestamp": 1642229965,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 21,
			"ext": "",
			"amount": 0,
			"tx_len": 230,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xbb654d3c3be4e0d64c071c6f5035ade858e04871c16e92bc21931dfe88694d04",
			"last_tx_nonce": 26,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x010000002e000000543830303030356362393166363566363466363234373835326131343139333037613934306666353037653336326400000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unvoteNode"
		}
	},
	"tx_size": 230,
	"sequence_id": "-2023431605716591646",
	"errmsg": "OK",
	"tx_hash": "0xbb654d3c3be4e0d64c071c6f5035ade858e04871c16e92bc21931dfe88694d04"
}

# 获取投票者分红信息

您给矿工投票之后,可以获取相应的投票分红,分红比例由被投票矿工设置。

投票者分红不是立刻可以查询,在投票之后的6小时可以查询投票者分红。

请求方法

topj.queryVoterDividend

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
nodeAddress - String 投票者账户地址。

返回参数

参数名称 类型 说明
accumulated Uint64 投票者分红总额的整数部分。单位uTOP。
accumulated_decimals Uint32 投票者分红总额的小数部分。单位10^-6 uTOP。
issue_time Uint64 投票者分红发放时间。
last_claim_time Uint64 投票者上次领取分红的时钟高度。
node_dividend List 被投票矿工的分红信息。
account_addr String 被投票矿工账户地址。
accumulated Uint64 被投票矿工分给该投票者的分红整数部分。单位uTOP。
accumulated_decimals Uint32 被投票矿工分给该投票者的分红小数部分。单位10^-6 uTOP。
issue_time Uint64 被投票矿工给该投票者的分红发放时间。
last_claim_time Uint64 被投票矿工分红上次被领取的时钟高度。
unclaimed Uint64 被投票矿工分给该投票者未领取的分红整数部分。单位uTOP。
unclaimed_decimals Uint32 被投票矿工分给该投票者未领取的分红小数部分。单位10^-6 uTOP。
unclaimed Uint64 投票者未领取的分红总额整数部分。单位uTOP。
unclaimed_decimals Uint32 投票者未领取的分红总额小数部分。单位10^-6 uTOP。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.VoterDividendResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryVoterDividend {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<VoterDividendResponse> result = topj.queryVoterDividend(account, account.getAddress());
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"node_dividend": [{
			"last_claim_time": 0,
			"account_addr": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"unclaimed": 144,
			"issue_time": 6896169,
			"unclaimed_decimals": 678682,
			"accumulated": 144,
			"accumulated_decimals": 678682
		}],
		"last_claim_time": 0,
		"unclaimed": 144,
		"issue_time": 6896169,
		"unclaimed_decimals": 678682,
		"accumulated": 144,
		"accumulated_decimals": 678682
	},
	"sequence_id": "1930283999220882257",
	"errmsg": "OK"
}

# 领取投票者分红

系统每12小时结算一次投票者分红,将投票人分红自动发放到分红池。

投票人12小时内可以申请提现一次,发起提现申请后立即到账。

请求方法

topj.claimVoterDividend

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 投票者账户对象。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ClaimVoterDividend {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.claimVoterDividend(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x015e5aea769d3731c859ecccce438a9f32a38500c50601682ad1b0ce9d7adec60a216c460f52742e4000cd802cae7875058f77b2a71119012c00c36fadd5e11466",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 8346055492206021528,
         "last_tx_nonce" : 11,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603788080,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "claimVoterDividend",
               "action_param" : "",
               "action_size" : 84,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T20000MT3itmNbWs4XYn8R1NUcoucmppJwN7qE69@228"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x015ccae65496623557522ea5553db507f5c81ee854046d207f5cfd38bd04ab1d",
         "tx_len" : 309,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 21,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "52b68c8db349e20199be2afbe9e78938f1f31ea75e73695fac3e0dd8bf28f1d8",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 3,
            "unit_hash" : "20fac0960687f4d70ed4c124daa785891d3935377daae758d58240e94a9398ff",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 20,
            "tx_fee" : 0,
            "unit_hash" : "2e859716a101520de03ffd09181c64d8482f380fe6da959105d99ab1982d72db",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 927
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "86"
}

# 获取单个矿工奖励信息

矿工奖励包括矿工工作奖励及选票奖励。

请求方法

topj.queryNodeReward

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
nodeAddress - String 矿工账户地址。

返回参数

参数名称 类型 说明
accumulated Uint64 奖励总额的整数部分。单位uTOP。
accumulated_decimals Uint32 奖励总额的小数部分。单位10^-6 uTOP。
issue_time Uint64 每个矿工奖励发放时的时钟高度。
last_claim_time Uint64 上次领取奖励的时钟高度。
unclaimed Uint64 未领取奖励的整数部分。单位uTOP。
unclaimed_decimals Uint64 未领取奖励的小数部分。单位10^-6 uTOP。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.NodeRewardResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<NodeRewardResponse> result = topj.queryNodeReward(account, account.getAddress());
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"last_claim_time": 0,
		"unclaimed": 1001933967,
		"issue_time": 6891868,
		"unclaimed_decimals": 793241,
		"accumulated": 1001933967,
		"accumulated_decimals": 793241
	},
	"sequence_id": "-4003021241813571072",
	"errmsg": "OK"
}

# 获取所有矿工奖励信息

请求方法

topj.queryAllNodeReward

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。

返回参数

参数名称 类型 说明
accumulated Uint64 矿工奖励总额,单位uTOP。
issue_time Uint64 奖励发放时的时钟高度。
last_claim_time Uint64 上次领取奖励的时钟高度。
unclaimed Uint64 未领取的奖励,单位uTOP。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.NodeRewardResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.util.Map;

public class QueryAllNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<Map<String, NodeRewardResponse>> result = topj.queryAllNodeReward(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "T8000066ab344963eaa071f9636faac26b0d1a39900325" : {
         "accumulated" : 188072630515731,
         "accumulated_decimals" : 209604,
         "issue_time" : 3533760,
         "last_claim_time" : 0,
         "unclaimed" : 188072630515731,
         "unclaimed_decimals" : 209604
      },
      "T8000085a8e8acd53c72dca85dcb002a6710796975b4ba" : {
         "accumulated" : 135157655656316,
         "accumulated_decimals" : 441988,
         "issue_time" : 3533760,
         "last_claim_time" : 0,
         "unclaimed" : 135157655656316,
         "unclaimed_decimals" : 441988
      }
   },
   "errmsg" : "ok",
   "errno" : 0,
   "sequence_id" : "49"
}

# 领取矿工奖励

每12小时最多领取一次。

请求方法

topj.claimNodeReward

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 矿工账户对象。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ClaimNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.claimNodeReward(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01a28b0ed68e2ead15083616945a92e737be520eb73ab4bb8700d9e16b0f5d4d797068762f3fc5ea060064f5e0694b139a57a5cc96a898f60b2bcae2344b4f3775",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 2325913416141072335,
         "last_tx_nonce" : 4,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603797213,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "claimNodeReward",
               "action_param" : "",
               "action_size" : 81,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T20000MT3itmNbWs4XYn8R1NUcoucmppJwN7qE69@155"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T8000085a8e8acd53c72dca85dcb002a6710796975b4ba"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x92a7f8d2456d063ff772a97e4432481d28f9d2e9b3c876cf8e3ccbfa8cdf5c96",
         "tx_len" : 306,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 11,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "287bbf07214842d62c6239747c7168b941c46dbf6aa6e84d9de2b80668533cba",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 70,
            "unit_hash" : "00f4f97eaa3d080d05d6103540c4022f93789af7315db03505f71848fddb0d90",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 10,
            "tx_fee" : 0,
            "unit_hash" : "34ee08c46b7501a859f45bb057e58d8a1d2a73a26d2ca778dbcaed0892d2f751",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 918
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "26"
}

# 提案管理

# 提交提案

链上治理时,首先需要提交链上治理提案。

任何用户可以发起提案,只要质押一定的TOP token即可。

除了最低交易保证金100,000 uTOP token,调用Beacon系统合约交易,需要扣除100*10^6 uTOP token的交易手续费。

因此提交提案前请确保您的账户里至少有100.1*10^6 uTOP token的余额。

# 链上治理参数修改提案

通过提案对链上治理参数进行修改。

# 社区基金管理提案

系统将治理奖励和零工作量节点奖励发放至社区基金账户,社区用户可以通过社区基金管理提案将账户中的余额转账至销毁账户,提案经过TCC表决通过后,销毁即生效。

社区基金账户地址:T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0。

销毁账户地址:T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug。

请求方法

topj.submitProposal

请求参数

参数名称 是否必选 默认值 类型 说明
proposal_type - Uint8 提案类型:1--链上治理参数修改提案;2--社区基金管理提案。
target - String 当提案类型为链上治理参数修改提案时,target为链上治理参数名称;
当提案类型为社区基金管理提案时,target为接受转账账户地址,销毁账户地址:T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug。
value - String 当target为链上治理参数时,value为修改后的值。
当target为接受转账账户地址,value为转账金额,单位uTOP。
proposal_deposit - Uint64 提案保证金,链上治理参数,当前最低为0。
effective_timer_height - Uint64 提案通过后生效时钟高度。如生效始终高度小于提案通过时的始终高度,那么提案在通过后会立刻生效。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class SubmitProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.submitProposal(account, BigInteger.valueOf(1), "T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug", "T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ua", BigInteger.valueOf(100000000L), BigInteger.valueOf(18400));
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x00055639267a80ec634048de50017a194407e092a849f3689fb4a907d4787ad3da3a0c99344f19366204a45cb4c0acd456d95a63f5c5671fc6e4efb75cd0591074",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 17353520882089532145,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603797973,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "submitProposal",
               "action_param" : "0x0d0000006d696e5f766f7465735f6e756d010000003101e803000000000000",
               "action_size" : 115,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "0x0000000000e1f50500000000",
               "action_size" : 78,
               "action_type" : 0,
               "tx_sender_account_addr" : "T80000fd4f433c036268f17a1b4204ea907e70618d030e"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x7d46fcbf2932605d06a83249a73843f2429b7f681fb3a1b39aff6d5378c557e6",
         "tx_len" : 352,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 14,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "92e0cc560569c3fef734e30e228528d59dbed054b68964dd9fb5e1c358acb82f",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 54,
            "unit_hash" : "80bb6ada286f4ffc1235fef5151a82ff8fad78ee797af6d064d0827d60827d90",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 13,
            "tx_fee" : 100000000,
            "unit_hash" : "c9aadf4688b1bce6337ffd77b1ef06edb148cda682e7b5cac750bb8e4064c5bb",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 1056
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "31"
}

# 撤回提案

提案只能由对应的提案者撤回。

请求方法

topj.withdrawProposal

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
proposalId - String 提案ID。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class WithdrawProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        ResponseBase<XTransactionResponse> result = topj.withdrawProposal(account, proposal.getProposalId());
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01cea8b3328ae1bc2c4ced3a584d2acb895938754859e46a89fbdd954e2488947e12ab0732457ed9ccfc91e2ba23bee2e1b96df3d8c6625143a33c6353d897fe9b",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 1339320303636985063,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1604047180,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "withdrawProposal",
               "action_param" : "0x0100000031",
               "action_size" : 91,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0xbeb7b03488646c051485b5979cba9ab2c30a75d568677c30182d1db932fa4763",
         "tx_len" : 316,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 9,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "0392946766b6a9908afb1950a71d9e25ede336d3bfb18bd8c5afc23c197acd76",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 2,
            "unit_hash" : "2326f7ff4d666fbc1a21125ccd90d11f36db47ef8f2eb4938a13155418b25b4a",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 8,
            "tx_fee" : 100000000,
            "unit_hash" : "a310bca7c898a0417fc34730a1e22595d3f2c5186f133a4018105e28faaa79a6",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 948
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "27"
}

# 获取提案详情

请求方法

topj.queryProposal

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 账户对象。
proposalId - String 提案ID。

返回参数

参数名称 类型 说明
effective_timer_height Uint64 提案通过后生效时钟高度。如生效始终高度小于提案通过时的始终高度,那么提案在通过后会立刻生效。
expire_time String 提案失效时间,提案在259200个时钟高度内没有被TCC通过或者否决,提案将失效。
priority Uint8 提案优先级:1--Normal;2--Important;3--Critical。
proposal_deposit Uint64 提案保证金,单位uTOP。
proposal_id String 提案ID,系统自动生成,唯一。
proposal_type Uint8 提案类型:1--修改链上治理参数提案;2--社区基金管理提案。
proposer_account_addr String 提案发起者账户地址。
target String 当提案类型为修改链上治理参数提案时,target为链上治理参数名称,链上治理参数请参见 链上治理参数说明
当提案类型为社区基金管理提案时,target为接受转账账户地址,销毁账户地址为:T-b-gkhLhFJXVN3ZPQYZxphja93BEUtwKRdden。
value String 当target为链上治理参数时,value为修改后的值。
当target为接受转账账户地址,value为转账金额,单位uTOP。
voting_status Uint16 该提案投票表决状态:0--未开始;8--进行中;9--失败;10--成功。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);

        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        ResponseBase<Proposal> result = topj.queryProposal(account, proposal.getProposalId());
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
    "data" : {
      "1":{
	      "effective_timer_height": 1010110,
	      "expire_time": 1000
	      "priority": 3,
	      "proposal_deposit": 400,
	      "proposal_id": 1,
	      "proposal_type": 1,
         "proposer_account_addr" : "T80000fd4f433c036268f17a1b4204ea907e70618d030v",
	      "target": archive_deposit,
	      "value": 1000,
	      "voting_status": 0
      }
   },
   "errmsg" : "ok",
   "errno" : 0,
   "sequence_id" : "3"
}

# TCC表决提案

对提案投票前,可先获取提案详细信息了解提案。

只有TCC委员对提案有表决权,表决通过的规则:需2/3的委员通过,且反对委员不超过20%。

提案表决通过后,且没有被否决,将形成立法命令,发给全网节点。

提案被表决通过后,系统将自动删除提案,无法查询提案。

请求方法

topj.tccVote

请求参数

参数名称 是否必填 默认值 类型 说明
account - Account 投票者账户对象。
proposalId - String 提案ID。
proposalClientAddress - String 提案者账户地址。
option - Boolean 表决意见:true--赞成;false--反对。

返回参数

请参见 交易体对象说明

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class TccVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        String clientAddress3 = "T80000fd4f433c036268f17a1b4204ea907e70618d030e";
        ResponseBase<XTransactionResponse> result = topj.tccVote(account, proposal.getProposalId(), clientAddress3, true);
        System.out.println(JSONObject.toJSON(result));
    }
}

返回样例

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x011ba5097a4b5a1f54776ec20bf2ca002fe259c51ff9f72a36882e1985239008e97ac8d49d12f768c1a2abadaf3b5e368a4ffeb6ab64c68f323192155fd1116409",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 11205396108775716568,
         "last_tx_nonce" : 6,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1604050651,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "tccVote",
               "action_param" : "0x010000003501",
               "action_size" : 83,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x3ba14855d285087e60f257f703c1b9f070afa7d1a81c05a5662b4a2fe9f0320e",
         "tx_len" : 308,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 14,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "540746c16ac538de15f3d1f1a734ead7576fbd94dd99a5b8e5706efbe3aa49b5",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 452,
            "unit_hash" : "5089993bf9ea2c74e5d82fd6ab19fa0dd13a56b7e506abd17aca2645f655f21e",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 13,
            "tx_fee" : 100000000,
            "unit_hash" : "113cd7f87440097999b01e54aba194d94d8784bba49f3cd4b40f86a05c10fa78",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 924
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "11"
}

# 工具方法

# 解析出转账交易体中的amount和note数据

解析出转账交易体中的amount和note数据,并赋值在“TransferActionParam”对象中。

请求方法

TransferActionParam.decode

请求参数

参数名称 是否必填 默认值 类型 说明
actionParam - String 参数内容。

返回参数

无返回,数据直接赋值对象体中。

请求样例

package org.sawyer;

import org.topj.account.Account;
import org.topj.core.Topj;
import org.topj.methods.Model.TransferActionParam;
import org.topj.methods.response.ResponseBase;
import org.topj.methods.response.tx.XTransactionResponse;
import org.topj.procotol.http.HttpService;
import org.topj.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class main {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://192.168.50.26:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("ec8519c723649ab2170807d39a9d01be1a6197266cfe39b4cc66c0433df85321");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> transferResponseBase = topj.transfer(account,"T800002276a7d58218ac4978733e5cca927a7d86cb7c87", BigInteger.valueOf(140), "hello top");
        TransferActionParam transferActionParam = new TransferActionParam();
        transferActionParam.decode(transferResponseBase.getData().getOriginalTxInfo().getReceiverAction().getActionParam());
    }
}

返回样例

无。

# 判断交易是否成功

请求方法

topj.getTxStatus

以转账交易为例:

  • 返回的对象中,获取 XTransaction 对象,获取交易 hash;
  • 然后调用 topj.getTxStatus(),返回 success 则表示交易成功,failure 表示失败,pending 表示交易仍在执行中,null 表示查不到交易。

请求参数

参数名称 是否必填 默认值 类型 说明
account - String 账户地址。
txHash - String 交易哈希。

返回参数

参数名称 类型 说明
data
tx_consensus_state Object 交易共识结果。
跨账户交易会进行三次共识,所以会返回三个 unit 的信息;单账户交易只返回只在交易发送账户下进行一次共识,所以只返回"confirm_unit_info"。
recv_block_info Object 打包 recv 交易的 table 块信息。
used_gas Uint32 用户合约交易,交易第二次共识后,扣除接收方账户应承担的的 gas。单位为 Tgas。
account String table地址
height Uint64 receive 交易所在的 table 块的高度。
confirm_block_info Object 打包 confirm 交易的 table 块信息。
used_deposit Uint32 交易第三次共识结束后,因发送方账户 gas 不足以支付交易花费而扣除的发送方账户的交易保证金,单位为 uTOP。
exec_status String 交易发送方共识状态:
success--成功;
failure--失败。
recv_tx_exec_status String 交易发送方共识状态:
success--成功;
failure--失败。
used_gas Uint32 用户合约交易,交易第三次共识结束后,扣除的发送方账户 gas。
如果合约用户已支付一部分 gas,那么此处扣除整个交易所消耗的 gas 的剩余部分;如果合约无法支付其应承担的 gas,那么此处扣除整个交易消耗的 gas。单位为 Tgas。
account String table 地址。
height Uint64 confirm 交易所在的 table 块的高度。
send_block_info Object 打包 send 交易的 table 块信息。
tx_fee Uint64 对于调用 Beacon 系统合约交易(注册矿工相关、提案相关、启动节点进程入网),系统自动从交易发送方账户中扣除 100*10^6 uTOP token 作为交易手续费,并销毁。
used_deposit Uint64 发送交易消耗的交易保证金。
used_gas Uint32 交易第一次共识扣除的 gas,单位为 Tgas。
对于非调用用户合约的跨账户交易,交易所消耗的 gas 全部由发送方承担,在发送方 gas 足够的情况下,会在第一轮共识就扣完交易所需要的 gas;在 gas 不足的情况下,第一轮共识会扣除发送方账户可用的 gas,剩余 gas 在第三轮共识扣除交易保证金兑换 gas 支付交易费用。
account String table 地址。
height Uint64 send 交易所在的 table 块的高度。
failure String 交易执行失败。
success String 交易执行成功。
original_tx_info Object 原始交易信息。
note String 交易备注。
receiver_account String 交易接受方账户地址。
premium_price Uint32 预留字段,默认为“0”。
authorization String 交易体签名。
from_ledger_id Uint16 预留字段,默认为"0"。
send_timestamp Uint64 交易发送时间戳。
token_name String token 符号,比如 top 为 TOP。
tx_random_nonce Uint64 随机数字。默认为"0",暂未使用。
tx_type Uint16 交易类型,不同的交易类型,action 中 action_param(执行内容)及 action type(执行类型)不同。
xtransaction_type_run_contract = 3, // 调用智能合约
xtransaction_type_transfer = 4, // 转账
xtransaction_type_vote = 20, //投票
xtransaction_type_abolish_vote = 21,//取消投票
xtransaction_type_pledge_token_gas = 22, // 锁定 TOP token 兑换 gas
xtransaction_type_redeem_token_gas = 23, // 解锁兑换 gas 锁定的 TOP token
xtransaction_type_pledge_token_vote = 27, // 锁定 TOP token 兑换选票
xtransaction_type_redeem_token_vote = 28, // 解锁兑换选票锁定的 TOP token
ext String 预留字段,用于扩展,默认为空字符串。
amount String table 地址。
tx_len Uint16 交易大小。交易消耗的 gas 与交易大小相关。
edge_nodeid String edge 节点的 id。
tx_structure_version Uint32 交易结构版本号。默认为"0",暂未使用。
tx_hash String 交易 hash 的十六进制。
last_tx_nonce Uint32 交易发送方上次交易的 nonce。
sender_action_param String 发送方执行内容。不同 action type 执行内容的序列化请参见 action param 序列化
last_tx_hash Uint64 交易发送方上次交易的 xx64hash,用于交易的排序和去重。
tx_deposit Uint32 交易保证金,单位为 uTOP。
sender_action_name String 预留字段,默认为空字符串。
tx_expire_duration Uint16 交易到期时长,超过则被丢弃,默认为 100s。
receiver_action_param String 接收方执行内容。不同 action type 执行内容的序列化请参见 action param 序列化
sender_account String 交易发送方账户地址。
to_ledger_id Uint16 预留字段,默认为"0"。
challenge_proof String 预留字段,默认为空字符串。
receiver_action_name String 调用合约时,合约的函数名。
其中,系统合约函数请参见 系统智能合约 API。非合约交易时,默认为空。
tx_size String 交易 size。
sequence_id String 客户端会话次数,递增。
errmsg String 错误信息。
tx_hash String 交易 hash 的十六进制。

请求样例

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class GetTxStatus {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> transferResponseBase = topj.transfer(account,"T00000LZYyjZmvB7ZDXpDQqC9feE18o3cSFjL82Q", BigInteger.valueOf(140), "hello top");
        String txHash = transferResponseBase.getData().getOriginalTxInfo().getTxHash();
        String isSuccess = topj.getTxStatus(account, txHash);
        System.out.println("transfer hash >> " + txHash + " >> is success > " + isSuccess);
        System.out.println(JSON.toJSON(transferResponseBase));
    }
}

返回样例

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@1",
				"height": 90
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 174
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 492,
				"account": "Ta0000@44",
				"height": 171
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "hello top",
			"receiver_account": "T00000LZYyjZmvB7ZDXpDQqC9feE18o3cSFjL82Q",
			"premium_price": 0,
			"authorization": "0x009ee17001b9006147e9a33852c1595ad9e363757e4cd9fc09060874dba0c6f0036e84566f6a842890f24046f3143f73c891b3d5901a31957797e2a6a2f9776aa4",
			"from_ledger_id": 0,
			"send_timestamp": 1642150847,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 4,
			"ext": "",
			"amount": 140,
			"tx_len": 164,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xeccb83f4345a9fc037c9946bf0f7c4ba859a0af048407dc7b7adcf2ede410846",
			"last_tx_nonce": 21,
			"sender_action_param": "0x03000000544f508c00000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x03000000544f508c00000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 164,
	"sequence_id": "-4567257279157316188",
	"errmsg": "OK",
	"tx_hash": "0xeccb83f4345a9fc037c9946bf0f7c4ba859a0af048407dc7b7adcf2ede410846"
}

# 交易返回体数据结构

{
    "data":{
        "original_tx_info":{
            "authorization":"0x01aefd0a118c48fd7846f3ee05a2728a55141ebf3fe94e6076cd1fd1bef295140f356bb10a12dd6731d8ab50332d57ced26f6379162d0eb8fd87871603d8380056",
            "challenge_proof":"",
            "ext":"",
            "from_ledger_id":0,
            "last_tx_hash":"11448926042541027033",
            "last_tx_nonce":3,
            "note":"",
            "premium_price" : 0,
            "receiver_action":{
                "action_authorization":"",
                "action_ext":"",
                "action_hash":0,
                "action_name":"registerNode",
                "action_param":"0x040000006564676508000000746f704e6f6465310a0000007075626c6963206b6579",
                "action_size":116,
                "action_type":5,
                "tx_receiver_account_addr":"T2000138DSqqwBWkHKxkVuCq3htW47BGtJRCM2paf@0"
            },
            "send_timestamp":1600766121,
            "sender_action":{
                "action_authorization":"",
                "action_ext":"",
                "action_hash":0,
                "action_name":"",
                "action_param":"0x000000000010a5d4e800000000000000",
                "action_size":82,
                "action_type":0,
                "tx_sender_account_addr":"T8000066ab344963eaa071f9636faac26b0d1a39900325"
            },
            "to_ledger_id":0,
            "tx_deposit":300000,
            "tx_expire_duration":100,
            "tx_hash":"0x4ce54b11e728fbd65745873a9e831d39516fd0ea326ef055de76a9efd8d25783",
            "tx_len":357,
            "tx_random_nonce":0,
            "tx_structure_version":2,
            "tx_type":3,
            "xx64Hash":"0xa1b759352d90776c"
        },
        "tx_consensus_state":{
            "confirm_unit_info":{
                "exec_status":"",
                "height":0,
                "tx_exec_status":"",
                "unit_hash":"f45195cc04590c98aa12d8676bd5585de291620e1b76377ec46d0f1d8376a302",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":0
            },
            "recv_unit_info":{
                "height":3,
                "unit_hash":"b76a433d5a53392cd811f4d2ae06f357c49fd89cf97efdb955033723aaea1c4f",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":0
            },
            "send_unit_info":{
                "height":6,
                "tx_fee":100000000,
                "unit_hash":"a39ef9be02b3c301f50aeeddc1c474871f47104dbc4ef063fda9892a51dc99b3",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":1071
            }
        }
    },
    "errmsg":"ok",
    "errno":0,
    "sequence_id":"1600766121429"
}

# 交易体对象说明

所有交易体对象一致,如下表所示。

参数名称 类型 说明
data
tx_consensus_state Object 交易共识结果。
跨账户交易会进行三次共识,所以会返回三个 unit 的信息;单账户交易只在交易发送账户下进行一次共识,所以只返回"confirm_block_info"。
recv_block_info object 打包 recv 交易的 table 块信息。
used_gas Uint64 用户合约交易,交易第二次共识后,扣除接收方账户应承担的的 gas。单位为 Tgas。
account String table 地址。
height Uint64 receive 交易所在的 table 块的高度。
confirm_block_info object 打包 confirm 交易的 table 块信息。
used_deposit Uint64 交易第三次共识结束后,因发送方账户 gas 不足以支付交易花费而扣除的发送方账户的交易保证金,单位为 uTOP。
exec_status String 交易最终共识结果:
success:成功
failure:失败
recv_tx_exec_status String 交易接收方共识结果:
success:成功
failure:失败
交易接收方共识失败或拒绝执行,通常在执行合约交易的时候会出现拒绝共识的情况。例如,注册矿工,矿工保证金低于最低要求,合约将执行失败。
used_gas Uint64 用户合约交易,交易第三次共识结束后,扣除的发送方账户 gas。
如果合约用户已支付一部分 gas,那么此处扣除整个交易所消耗的 gas 的剩余部分;如果合约无法支付其应承担的 gas,那么此处扣除整个交易消耗的 gas。单位为 Tgas。
account String table 地址。
height Uint64 confirm 交易所在的 table 块的高度。
send_block_info object 打包 send 交易的 table 块信息。
tx_fee Uint64 对于调用 Beacon 系统合约交易(注册矿工相关、提案相关、启动节点进程入网),系统自动从交易发送方账户中扣除 100*10^6 uTOP token 作为交易手续费,并销毁。
used_deposit Uint64 发送交易消耗的交易保证金。
used_gas Uint64 交易第一次共识扣除的 gas,单位为 Tgas。
对于非调用用户合约的跨账户交易,交易所消耗的 gas 全部由发送方承担,在发送方 gas 足够的情况下,会在第一轮共识就扣完交易所需要的 gas;在 gas 不足的情况下,第一轮共识会扣除发送方账户可用的 gas,剩余 gas 在第三轮共识扣除交易保证金兑换 gas 支付交易费用。
account String table 地址。
height Uint64 send 交易所在的 table 块的高度。
failure String 交易执行失败。
success String 交易执行成功。
original_tx_info Object 原始交易信息。
note String 交易备注。
receiver_account String 交易接受方账户地址。
premium_price Uint32 预留字段,默认为“0”。
authorization String 交易体签名。
from_ledger_id Uint16 预留字段,默认为“0”。
send_timestamp Uint64 交易发送时间戳。
token_name String token 符号,比如 top 为 TOP。
tx_random_nonce Uint32 随机数字。默认为“0”,暂未使用。
tx_type Uint16 交易类型,不同的交易类型,action 中 action_param(执行内容)及 action type(执行类型)不同。
xtransaction_type_run_contract = 3, // 调用智能合约
xtransaction_type_transfer = 4, // 转账
xtransaction_type_vote = 20, // 投票
xtransaction_type_abolish_vote = 21,// 取消投票
xtransaction_type_pledge_token_gas = 22, // 锁定 TOP token 兑换 gas
xtransaction_type_redeem_token_gas = 23, // 解锁兑换 gas 锁定的 TOP token
xtransaction_type_pledge_token_vote = 27, // 锁定 TOP token 兑换选票
xtransaction_type_redeem_token_vote = 28, // 解锁兑换选票锁定的 TOP token
ext String 预留字段,用于扩展,默认为空字符串。
amount Uint64 交易金额。
tx_len Uint16 交易大小。交易消耗的 gas 与交易大小相关。
edge_nodeid String 转发交易的 edge 节点 id,目前未使用。
tx_structure_version Uint32 交易结构版本号。默认为"2"
tx_hash String 交易 hash 的十六进制。
last_tx_nonce String 上一笔交易 nonce。
sender_action_param String 发送方执行内容。不同 action type 执行内容的序列化请参见 action param 序列化
last_tx_hash Uint64 交易发送方上次交易的 xx64hash,用于交易的排序和去重。
tx_deposit Uint32 交易保证金,单位为 uTOP。
sender_action_name String 预留字段,默认为空字符串。
tx_expire_duration Uint16 交易到期时长,超过则被丢弃,默认 100s。
receiver_action_param String 接收方执行内容。不同 action type 执行内容的序列化请参见 action param 序列化
sender_account String 交易发送方账户地址。
to_ledger_id Uint16 预留字段,默认为"0"。
challenge_proof String 预留字段,默认为空字符串。
receiver_action_name String 调用合约时,合约的函数名。 其中,系统合约函数请参见 系统智能合约 API。非合约交易时,默认为空。
sequence_id String 客户端会话次数,递增。
errmsg String 错误信息。
errno Uint64 错误编号。

# 示例代码

合约代码示例:

function init()
    create_key('temp_1')
    create_key('temp_2')
    hcreate('hmap')
    set_key('temp_1', '0')
    set_key('temp_2', '0')
    hset('hmap', 'key', 'val')
    hcreate('empty_map')
    create_key('map_len')
    create_key('map_str')

    lcreate('mlist')
    rpush('mlist', '44')
end

function opt_map(key, value)
    hset('hmap', toText(key), toText(value))
    lpush("mlist", toText(value))
end

function check_map(key)
    local map_len = hlen('hmap')
    set_key('temp_1', toText(map_len))
    local map_str = hget('hmap', toText(key))
    set_key('temp_2', toText(map_str))
    hdel('hmap', toText(key))
end

function get_empty_map()
    set_key('map_len', toText(hlen('empty_map')))
    set_key('map_str', toText(hget('empty_map', 'unexist')))
end

function get_empty_key()
    set_key('map_str', toText(hget('empty_map', '')))
end

function del_empty_key()
    hdel('hmap', '')
    set_key('map_len', toText(hlen('empty_map')))
end

function del_not_exist_key()
    hdel('hmap', 'unexist')
    set_key('map_len', toText(hlen('empty_map')))
end