Java接口API

getObject

键值获取

public byte[] getObject(byte[] key)

输入

参数

说明

key

查询的key值

输出

参数

说明

value

key值查询成功,返回value值;为null时,查询失败

putObject

键值存储

public void putObject(byte[] key, byte[] value)

输入

参数

说明

key

存入的key值

value

存入key值对应的value值

输出

参数

说明

void

操作失败时,可捕捉异常;否则,成功

deleteObject

键值删除

public void deleteObject(byte[] key)

输入

参数

说明

key

将要删除的key值

输出

参数

说明

void

操作失败时,可捕捉异常;否则,成功

queryTx

交易查询

public Contract.Transaction queryTx(String txid)

输入

参数

说明

txid

待查询的txid

输出

参数

说明

tx

查询交易成功, 得到此txid的transaction;查询失败,抛出异常

queryBlock

区块查询

public Contract.Block queryBlock(String blockid)

输入

参数

说明

blockid

待查询的blockid

输出

newIterator

迭代器

public Iterator<ContractIteratorItem> newIterator(byte[] start, byte[] limit)

输入

参数

说明

start

初始关键字

limit

结束关键字

输出

参数

说明

Iterator

Interator的接口

样例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
@ContractMethod
public Response getList(Context ctx) {
    byte[] start = ctx.args().get("start");
    if (start == null) {
        return Response.error("missing start");
    }

    byte[] limit = PrefixRange.generateLimit(start);
    Iterator<ContractIteratorItem> iter = ctx.newIterator(start, limit);
    int i = 0;
    while (iter.hasNext()) {
        ContractIteratorItem item = iter.next();
        String key = bytesToString(item.getKey());
        String value = bytesToString(item.getValue());
        ctx.log("item: " + i + ", key: " + key + ", value: " + value);
        i++;
    }

    return Response.ok("ok".getBytes());
}

transfer

从合约向其他地址转账

public void transfer(String to, BigInteger amount)

输入

参数

说明

to

收款地址

amount

数量

输出

transferAmount

调用合约方法向合约转账时,获取转账的数量

public BigInteger transferAmount()

输入

输出

参数

说明

BigInteger

数量

call

跨合约调用

public Response call(String module, String contract, String method, Map<String, byte[]> args)

输入

参数

说明

module

模块名

contract

合约名

method

合约方法

args

合约参数

输出

参数

说明

Response

合约返回值

crossQuery

跨链查询

public Response crossQuery(String uri, Map<String, byte[]> args)

输入

参数

说明

uri

跨链路由地址

args

合约参数

输出

参数

说明

Response

合约返回值