SDK:BUMO PHP SDK

37 篇文章 0 订阅
36 篇文章 6 订阅

BUMO PHP SDK

概述

本文档详细说明Bumo PHP SDK常用接口文档, 使开发者更方便地操作和查询BU区块链。

包引入

php必须是5.6或更高版本

  1. 下载Bumo PHP SDK包。
  2. 解压缩bumo-sdk-php-{版本号}.zip包。
  3. 再解压缩libs目录下的ed25519.zip包。
  4. 将php对应版本有ed25519.so库拷贝到其扩展目录下
  5. 在php的配置文件php.ini中添加“extension=ed25519.so”
  6. 执行以下命令引入包
composer require bumo/bumo-sdk:^{version}

例如:

composer require bumo/bumo-sdk:^v1.0.0

请求参数与响应数据格式

请求参数

接口的请求参数的类名,是服务名 + 方法名 + Request,比如: 账户服务下的getInfo接口的请求参数格式是AccountGetInfoRequest。

请求参数的成员,是各个接口的入参的成员。例如:账户服务下的getInfo接口的入参成员是address,那么该接口的请求参数的完整结构如下:

class AccountGetInfoRequest {
    $address; // string
}

响应数据

接口的响应数据的类名,是服务名 + 方法名 + Response,比如:账户服务下的getNonce接口的响应数据格式是AccountGetNonceResponse。

响应数据的成员,包括错误码、错误描述和返回结果,比如资产服务下的getNonce接口的响应数据的成员如下:

class AccountGetNonceResponse {
    $errorCode; // int
    $errorDesc; // string
    $result; // AccountGetNonceResult
}

说明:

  1. errorCode: 错误码。0表示无错误,大于0表示有错误
  2. errorDesc: 错误描述。
  3. result: 返回结果。一个结构体,其类名是服务名 + 方法名 + Result,其成员是各个接口返回值的成员,例如:账户服务下的getNonce接口的结果类名是AccountGetNonceResult,成员有nonce, 完整结构如下:
class AccountGetNonceResult {
    $nonce; // int64
}

使用方法

这里介绍SDK的使用流程,首先需要生成SDK实现,然后调用相应服务的接口,其中服务包括账户服务资产服务合约服务交易服务区块服务,接口按使用分类分为生成公私钥地址有效性校验查询广播交易相关接口。

生成SDK实例

调用SDK的接口getInstance来实现。

简单配置

调用如下:

$url = "http://seed1.bumotest.io";
$sdk = \src\SDK::getInstance($url);

超时配置

调用如下:

$url = "http://seed1.bumotest.io";
$sdkConfigure = new \src\model\request\SDKConfigure();
$sdkConfigure->setTimeOut(15000);
$sdk = \src\SDK::getInstanceWithConfigure($sdkConfigure);

生成公私钥地址

此接口生成BU区块链账户的公钥、私钥和地址,直接调用账户服务下的create接口即可,调用如下:

$account = $sdk->getAccountService();
$response = $account->create();
if (0 == $response->error_code) {
    echo $response->result->private_key . "\n";
    echo $response->result->public_key . "\n";
    echo $response->result->address . "\n";
}

有效性校验

此接口用于校验信息的有效性的,直接调用相应的接口即可,比如,校验账户地址有效性,调用如下:

// 初始化请求参数
$address = "buQemmMwmRQY1JkcU7w3nhruoX5N3j6C29uo";
$request = new \src\model\request\AccountCheckValidRequest();
$request->setAddress($address);

// 调用checkValid接口
$response = $sdk->getAccountService()->checkValid($request);
if(0 == $response->error_code) {
    echo $response->result->is_valid . "\n";
} else {
    echo "error: " . $response->error_desc . "\n";
}

查询

此接口用于查询BU区块链上的数据,直接调用相应的接口即可,比如,查询账户信息,调用如下:

// 初始化请求参数
$accountAddress = "buQemmMwmRQY1JkcU7w3nhruo%X5N3j6C29uo";
$request = new \src\model\request\AccountGetInfoRequest();
$request->setAddress(accountAddress);

// 调用getInfo接口
$response =  $sdk->getAccountService()->getInfo($request);
if ($response->error_code == 0) {
    $result = $response->result;
    echo json_encode($result) . "\n";
}
else {
    echo "error: " . $response->error_desc . "\n";
}

广播交易

广播交易是指通过广播的方式发起交易。广播交易包括以下步骤:

  1. 获取账户nonce值
  2. 构建操作
  3. 序列化交易
  4. 签名交易
  5. 提交交易

获取账户nonce值

开发者可自己维护各个账户nonce,在提交完一个交易后,自动递增1,这样可以在短时间内发送多笔交易,否则,必须等上一个交易执行完成后,账户的nonce值才会加1。接口详情请见getNonce,调用如下::

// 初始化请求参数
$senderAddress = "buQnnUEBREw2hB6pWHGPzwanX7d28xk6KVcp";
$getNonceRequest = new \src\model\request\AccountGetNonceRequest();
$getNonceRequest->setAddress($senderAddress);

// 调用getNonce接口
$getNonceResponse =  $sdk->getAccountService()->getNonce($getNonceRequest);

// 赋值nonce
if ($getNonceResponse->error_code == 0) {
   $result = $getNonceResponse->result;
   echo "nonce: " . $result->nonce . "\n";
}
else {
    echo "error" . $getNonceresponse->error_desc . "\n";
}

构建操作

这里的操作是指在交易中做的一些动作,便于序列化交易和评估费用。操作详情请见操作。例如,构建发送BU操作BUSendOperation,接口调用如下:

$senderAddress = "buQnnUEBREw2hB6pWHGPzwanX7d28xk6KVcp";
$destAddress = "buQsurH1M4rjLkfjzkxR9KXJ6jSu2r9xBNEw";
$buAmount = \src\common\Tools::BU2MO("10.9");

$operation = new \src\model\request\operation\BUSendOperation();
$operation->setSourceAddress($senderAddress);
$operation->setDestAddress($destAddress);
$operation->setAmount($buAmount);

序列化交易

该接口用于序列化交易,并生成交易Blob串,便于网络传输。其中nonce和operation是上面接口得到的,接口详情请见buildBlob,调用如下:

// 初始化变量
$senderAddress = "buQnnUEBREw2hB6pWHGPzwanX7d28xk6KVcp";
$gasPrice = 1000;
$feeLimit = \src\common\Tools::BU2MO("0.01");

// 初始化请求参数
$buildBlobRequest = new \src\model\request\TransactionBuildBlobRequest();
$buildBlobRequest->setSourceAddress($senderAddress);
$buildBlobRequest->setNonce($nonce + 1);
$buildBlobRequest->setFeeLimit($feeLimit);
$buildBlobRequest->setGasPrice($gasPrice);
$buildBlobRequest->addOperation($operation);

// 调用buildBlob接口
$buildBlobResponse = $sdk->getTransactionService()->buildBlob($buildBlobRequest);
if ($buildBlobResponse->error_code == 0) {
    $result = $buildBlobResponse->result;
    echo "txHash: " . $result->hash . ", blob: " . $result->transaction_blob . "\n";
} else {
    echo "error: " . $buildBlobResponse->error_desc . "\n";
}

签名交易

该接口用于交易发起者使用其账户私钥对交易进行签名。其中transactionBlob是上面接口得到的,接口详情请见sign,调用如下:

// 初始化请求参数
$senderPrivateKey = "privbyQCRp7DLqKtRFCqKQJr81TurTqG6UKXMMtGAmPG3abcM9XHjWvq";
$signRequest = new \src\model\request\TransactionSignRequest();
$signRequest->addPrivateKey($senderPrivateKey);
$signRequest->setBlob($transactionBlob);

// 调用sign接口
$signResponse = $sdk->getTransactionService()->sign($signRequest);
if ($signResponse->error_code == 0) {
    $result = $signResponse->result;
    echo json_encode($result, JSON_UNESCAPED_UNICODE) . "\n";
} else {
    echo "error: " . $signResponse->error_desc . "\n";
}

提交交易

该接口用于向BU区块链发送交易请求,触发交易的执行。其中transactionBlob和signResult是上面接口得到的,接口详情请见submit,调用如下:

// 初始化请求参数
$submitRequest = new \src\model\request\TransactionSubmitRequest();
$submitRequest->setTransactionBlob($transactionBlob);
$submitRequest->setSignatures($signResult->signatures);

// 调用submit接口
$response = $sdk->getTransactionService()->submit($submitRequest);
if (0 == $response->error_code) {
    echo "交易广播成功,hash=" . $response->result->hash . "\n";
} else {
    echo "error: " . $response->error_desc . "\n";
}

交易服务

交易服务主要是交易相关的接口,目前有5个接口:buildBlobevaluateFeesignsubmitgetInfo

buildBlob

注意: 调用buildBlob之前需要构建一些操作,详情见操作

  • 接口说明

    该接口用于序列化交易,生成交易Blob串,便于网络传输

  • 调用方法

    /**
    * Serialize the transaction
    * @param TransactionBuildBlobRequest $transactionBuildBlobRequest
    * @return TransactionBuildBlobResponse
    */
    public function buildBlob($transactionBuildBlobRequest);
    
  • 请求参数

    参数类型描述
    sourceAddressString必填,发起该操作的源账户地址
    nonceint64必填,待发起的交易序列号,函数里+1,大小限制[1, max(int64)]
    gasPriceint64必填,交易燃料单价,单位MO,1 BU = 10^8 MO,大小限制[1000, max(int64)]
    feeLimitint64必填,交易要求的最低的手续费,单位MO,1 BU = 10^8 MO,大小限制[1, max(int64)]
    operationBaseOperation[]必填,待提交的操作列表,不能为空
    ceilLedgerSeqint64选填,距离当前区块高度指定差值的区块内执行的限制,当区块超出当时区块高度与所设差值的和后,交易执行失败。必须大于等于0,是0时不限制
    metadataString选填,备注
  • 响应数据

    参数类型描述
    transactionBlobStringTransaction序列化后的16进制字符串
    hashString交易hash
  • 错误码

    异常错误码描述
    INVALID_SOURCEADDRESS_ERROR11002Invalid sourceAddress
    INVALID_NONCE_ERROR11048Nonce must be between 1 and max(int64)
    INVALID_DESTADDRESS_ERROR11003Invalid destAddress
    INVALID_INITBALANCE_ERROR11004InitBalance must be between 1 and max(int64)
    SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR11005SourceAddress cannot be equal to destAddress
    INVALID_ISSUE_AMMOUNT_ERROR11008AssetAmount this will be issued must be between 1 and max(int64)
    INVALID_DATAKEY_ERROR11011The length of key must be between 1 and 1024
    INVALID_DATAVALUE_ERROR11012The length of value must be between 0 and 256000
    INVALID_DATAVERSION_ERROR11013The version must be equal to or bigger than 0
    INVALID_MASTERWEIGHT _ERROR11015MasterWeight must be between 0 and max(uint32)
    INVALID_SIGNER_ADDRESS_ERROR11016Invalid signer address
    INVALID_SIGNER_WEIGHT _ERROR11017Signer weight must be between 0 and max(uint32)
    INVALID_TX_THRESHOLD_ERROR11018TxThreshold must be between 0 and max(int64)
    INVALID_OPERATION_TYPE_ERROR11019Operation type must be between 1 and 100
    INVALID_TYPE_THRESHOLD_ERROR11020TypeThreshold must be between 0 and max(int64)
    INVALID_ASSET_CODE _ERROR11023The length of key must be between 1 and 64
    INVALID_ASSET_AMOUNT_ERROR11024AssetAmount must be between 0 and max(int64)
    INVALID_BU_AMOUNT_ERROR11026BuAmount must be between 0 and max(int64)
    INVALID_ISSUER_ADDRESS_ERROR11027Invalid issuer address
    NO_SUCH_TOKEN_ERROR11030No such token
    INVALID_TOKEN_NAME_ERROR11031The length of token name must be between 1 and 1024
    INVALID_TOKEN_SYMBOL_ERROR11032The length of symbol must be between 1 and 1024
    INVALID_TOKEN_DECIMALS_ERROR11033Decimals must be between 0 and 8
    INVALID_TOKEN_TOTALSUPPLY_ERROR11034TotalSupply must be between 1 and max(int64)
    INVALID_TOKENOWNER_ERRPR11035Invalid token owner
    INVALID_CONTRACTADDRESS_ERROR11037Invalid contract address
    CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR11038ContractAddress is not a contract account
    INVALID_TOKEN_AMOUNT_ERROR11039Token amount must be between 1 and max(int64)
    SOURCEADDRESS_EQUAL_CONTRACTADDRESS_ERROR11040SourceAddress cannot be equal to contractAddress
    INVALID_FROMADDRESS_ERROR11041Invalid fromAddress
    FROMADDRESS_EQUAL_DESTADDRESS_ERROR11042FromAddress cannot be equal to destAddress
    INVALID_SPENDER_ERROR11043Invalid spender
    PAYLOAD_EMPTY_ERROR11044Payload cannot be empty
    INVALID_LOG_TOPIC_ERROR11045The length of a log topic must be between 1 and 128
    INVALID_LOG_DATA_ERROR11046The length of one piece of log data must be between 1 and1024
    INVALID_CONTRACT_TYPE_ERROR11047Type must be equal or bigger than 0
    INVALID_NONCE_ERROR11048Nonce must be between 1 and max(int64)
    INVALID_ GASPRICE_ERROR11049GasPrice must be between 1000 and max(int64)
    INVALID_FEELIMIT_ERROR11050FeeLimit must be between 1 and max(int64)
    OPERATIONS_EMPTY_ERROR11051Operations cannot be empty
    INVALID_CEILLEDGERSEQ_ERROR11052CeilLedgerSeq must be equal to or bigger than 0
    OPERATIONS_ONE_ERROR11053One of the operations cannot be resolved
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    METADATA_NOT_STRING_ERROR17001Metadata must be a string
    INPUT_NOT_STRING_ERROR17002Input must be a string
    INIT_INPUT_NOT_STRING_ERROR17003InitInput must be a string
    INVALID_REQUEST_ERROR17004Request is invalid
    INVALID_DELETE_FLAG_ERROR17005The deleteFlag is invalid
    SIGNERS_NOT_ARRAY_ERROR17006The signers should be an array
    INVALID_SIGNER_ERROR17007The signer is invalid
    TYPE_THRESHOLDS_NOT_ARRAY_ERROR17008The typeThresholds should be an array
  • 示例

    // 初始化变量
    $senderAddresss = "buQfnVYgXuMo3rvCEpKA6SfRrDpaz8D8A9Ea";
    $destAddress = "buQsurH1M4rjLkfjzkxR9KXJ6jSu2r9xBNEw";
    $buAmount = \src\common\Tools::BU2MO(10.9);
    $gasPrice = 1000;
    $feeLimit = \src\common\Tools::BU2MO(0.01);
    $nonce = 1;
    
    // 构建sendBU操作
    $operation = new \src\model\request\operation\BUSendOperation();
    $operation->setSourceAddress($senderAddresss);
    $operation->setDestAddress($destAddress);
    $operation->setAmount($buAmount);
    
    // 初始化请求参数
    $request = new \src\model\request\TransactionBuildBlobRequest();
    $request->setSourceAddress($senderAddresss);
    $request->setNonce($nonce);
    $request->setFeeLimit($feeLimit);
    $request->setGasPrice($gasPrice);
    $request->addOperation($operation);
    
    // 调用buildBlob接口
    $transactionBlob = null;
    $response = $sdk->getTransactionService()->buildBlob($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

evaluateFee

  • 接口说明

    该接口实现交易的费用评估

  • 调用方法

    /**
    * Evaluate the fee of a transaction
    * @param TransactionEvaluateFeeRequest $transactionEvaluateFeeRequest
    * @return TransactionEvaluateFeeResponse
    */
    public function evaluateFee($transactionEvaluateFeeRequest);
    
  • 请求参数

    参数类型描述
    sourceAddressString必填,发起该操作的源账户地址
    nonceint64必填,待发起的交易序列号,大小限制[1, max(int64)]
    operationBaseOperation[]必填,待提交的操作列表,不能为空
    signtureNumberInteger选填,待签名者的数量,默认是1,大小限制[1, max(uint32)]
    ceilLedgerSeqint64选填,距离当前区块高度指定差值的区块内执行的限制,当区块超出当时区块高度与所设差值的和后,交易执行失败。必须大于等于0,是0时不限制
    metadataString选填,备注
  • 响应数据

    参数类型描述
    txsTestTx[]评估交易集
  • 错误码

    异常错误码描述
    INVALID_SOURCEADDRESS_ERROR11002Invalid sourceAddress
    INVALID_NONCE_ERROR11045Nonce must be between 1 and max(int64)
    OPERATIONS_EMPTY_ERROR11051Operations cannot be empty
    OPERATIONS_ONE_ERROR11053One of the operations cannot be resolved
    INVALID_SIGNATURENUMBER_ERROR11054SignagureNumber must be between 1 and max(uint32)
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
    METADATA_NOT_STRING_ERROR17001Metadata must be a string
  • 示例

    // 初始化变量
    $senderAddresss = "buQnnUEBREw2hB6pWHGPzwanX7d28xk6KVcp";
    $destAddress = "buQfnVYgXuMo3rvCEpKA6SfRrDpaz8D8A9Ea";
    $buAmount = \src\common\Tools::BU2MO(10.9);
    $gasPrice = 1000;
    $feeLimit = \src\common\Tools::BU2MO(0.01);
    $nonce = 51;
    
    // 构建sendBU操作
    $buSendOperation = new \src\model\request\operation\BUSendOperation();
    $buSendOperation->setSourceAddress($senderAddresss);
    $buSendOperation->setDestAddress($destAddress);
    $buSendOperation->setAmount($buAmount);
    
    // 初始化评估交易请求参数
    $request = new \src\model\request\TransactionEvaluateFeeRequest();
    $request->addOperation($buSendOperation);
    $request->setSourceAddress($senderAddresss);
    $request->setNonce($nonce);
    $request->setSignatureNumber(1);
    $request->setMetadata(bin2hex("evaluate fees"));
    
    // 调用evaluateFee接口
    $response = $sdk->getTransactionService().evaluateFee($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

sign

  • 接口说明

    该接口用于实现交易的签名

  • 调用方法

    /**
    * Sign a transaction
    * @param TransactionSignRequest $transactionSignRequest
    * @return TransactionSignResponse
    */
    public function sign($transactionSignRequest);
    
  • 请求参数

    参数类型描述
    blobString必填,待签名的交易Blob
    privateKeysString[]必填,私钥列表
  • 响应数据

    参数类型描述
    signaturesSignature签名后的数据列表
  • 错误码

    异常错误码描述
    INVALID_BLOB_ERROR11056Invalid blob
    PRIVATEKEY_NULL_ERROR11057PrivateKeys cannot be empty
    PRIVATEKEY_ONE_ERROR11058One of privateKeys is invalid
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $issuePrivateKey = "privbyQCRp7DLqKtRFCqKQJr81TurTqG6UKXMMtGAmPG3abcM9XHjWvq";
    $transactionBlob = "0A246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370102118C0843D20E8073A56080712246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370522C0A24627551426A4A443142534A376E7A41627A6454656E416870466A6D7852564545746D78481080A9E08704";
    $request = new \src\model\request\TransactionSignRequest();
    $request->setBlob($transactionBlob);
    $request->addPrivateKey($issuePrivateKey);
    $response = $sdk->getTransactionService()->sign($request);
    if(0 == $response->error_code){
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    }else{
        echo "error: " . $response->error_desc;
    }
    

submit

  • 接口说明

    该接口用于实现交易的提交。

  • 调用方法

    /**
    * Submit a transaction to bu chain
    * @param TransactionSubmitRequest $transactionSubmitRequest
    * @return TransactionSubmitResponse
    */
    public function submit($transactionSubmitRequest);
    
  • 请求参数

    参数类型描述
    blobString必填,交易blob
    signatureSignature[]必填,签名列表
  • 响应数据

    参数类型描述
    hashString交易hash
  • 错误码

    异常错误码描述
    INVALID_BLOB_ERROR11056Invalid blob
    SIGNATURE_EMPTY_ERROR11067The signatures cannot be empty
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
    SIGNATURES_ARRAY_ERROR17009The signatures should be an array
    INVALID_SIGNATURE_ERROR17010The signature is invalid
  • 示例

    // 初始化请求参数
    $transactionBlob = "0A246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370102118C0843D20E8073A56080712246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370522C0A24627551426A4A443142534A376E7A41627A6454656E416870466A6D7852564545746D78481080A9E08704";
    $signature = new Signature();
    $signature->setSignData(
    "D2B5E3045F2C1B7D363D4F58C1858C30ABBBB0F41E4B2E18AF680553CA9C3689078E215C097086E47A4393BCA715C7A5D2C180D8750F35C6798944F79CC5000A");
    $signature->setPublicKey(
    "b0011765082a9352e04678ef38d38046dc01306edef676547456c0c23e270aaed7ffe9e31477");
    $request = new \src\model\request\\src\model\request\TransactionSubmitRequest();
    $request->setTransactionBlob($transactionBlob);
    $request->addSignature($signature);
    
    // 调用submit接口
    $response = $sdk->getTransactionService()->submit($request);
    if (0 == $response->error_code) { // 交易提交成功
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else{
        echo "error: " . $response->error_desc;
    }
    

getInfo

  • 接口说明

    该接口用于实现根据交易hash查询交易

  • 调用方法

    /**
    * Get the information of specific block
    * @param TransactionGetInfoRequest $transactionGetInfoRequest
    * @return TransactionGetInfoResponse
    */
    function getInfo($transactionGetInfoRequest);
    
  • 请求参数

    参数类型描述
    hashString交易hash
  • 响应数据

    参数类型描述
    totalCountint64返回的总交易数
    transactionsTransactionHistory[]交易内容
  • 错误码

    异常错误码描述
    INVALID_HASH_ERROR11055Invalid transaction hash
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $txHash = "1653f54fbba1134f7e35acee49592a7c29384da10f2f629c9a214f6e54747705";
    $request = new \src\model\request\TransactionGetInfoRequest();
    $request->setHash(txHash);
    
    // 调用getInfo接口
    $response = $sdk->getTransactionService()->getInfo($request);
    if ($response->error_code == 0) {
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

操作

操作是指在交易在要做的事情,在构建操作之前,需要构建操作。目前操作有10种,分别是 AccountActivateOperationAccountSetMetadataOperation、 AccountSetPrivilegeOperation、 AssetIssueOperation、 AssetSendOperation、 BUSendOperation、 ContractCreateOperation、 ContractInvokeByAssetOperation、 ContractInvokeByBUOperation、 LogCreateOperation

BaseOperation

BaseOperation是buildBlob接口中所有操作的基类。

成员变量类型描述
sourceAddressString选填,操作源账户地址
metadataString选填,备注

AccountActivateOperation

  • 功能

    该操作用于激活账户。AccountActivateOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    destAddressString必填,目标账户地址
    initBalanceint64必填,初始化资产,单位MO,1 BU = 10^8 MO, 大小(0, max(int64)]
    metadataString选填,备注

AccountSetMetadataOperation

  • 功能

    该操作用于设置账户metadata。AccountSetMetadataOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    keyString必填,metadata的关键词,长度限制[1, 1024]
    valueString必填,metadata的内容,长度限制[0, 256000]
    versionint64选填,metadata的版本
    deleteFlagBoolean选填,是否删除metadata
    metadataString选填,备注

AccountSetPrivilegeOperation

  • 功能

    该操作用于设置账户权限。AccountSetPrivilegeOperation继承于BaseOperation。

  • 费用

    feeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    masterWeightString选填,账户自身权重,大小限制[0, (Integer.MAX_VALUE * 2L + 1)]
    signersSigner[]选填,签名者权重列表
    txThresholdString选填,交易门限,大小限制[0, max(int64)]
    typeThresholdTypeThreshold[]选填,指定类型交易门限
    metadataString选填,备注

AssetIssueOperation

  • 功能

    该操作用于发行资产。AssetIssueOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是50.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    codeString必填,资产编码,长度限制[1, 64]
    assetAmountint64必填,资产发行数量,大小限制[0, max(int64)]
    metadataString选填,备注

AssetSendOperation

注意:若目标账户未激活,必须先调用激活账户操作。

  • 功能

    该操作用于转移资产。AssetSendOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    destAddressString必填,目标账户地址
    codeString必填,资产编码,长度限制[1, 64]
    issuerString必填,资产发行账户地址
    assetAmountint64必填,资产数量,大小限制[0, max(int64)]
    metadataString选填,备注

BUSendOperation

注意:若目标账户未激活,该操作也可使目标账户激活。

  • 功能

    该操作用于转移BU。BUSendOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    destAddressString必填,目标账户地址
    buAmountint64必填,资产发行数量,大小限制[0, max(int64)]
    metadataString选填,备注

ContractCreateOperation

  • 功能

    该操作用于创建合约。ContractCreateOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是10.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    initBalanceint64必填,给合约账户的初始化资产,单位MO,1 BU = 10^8 MO, 大小限制[1, max(int64)]
    typeInteger选填,合约的语种,默认是0
    payloadString必填,对应语种的合约代码
    initInputString选填,合约代码中init方法的入参
    metadataString选填,备注

ContractInvokeByAssetOperation

注意:若合约账户不存在,必须先创建合约账户。

  • 功能

    该操作用于转移资产并触发合约。ContractInvokeByAssetOperation继承于BaseOperation。

  • 费用

    FeeLimit要根据合约中执行交易来做添加手续费,首先发起交易手续费目前(2018.07.26)是0.01BU,然后合约中的交易也需要交易发起者添加相应交易的手续费。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    contractAddressString必填,合约账户地址
    codeString选填,资产编码,长度限制[0, 64];当为空时,仅触发合约;
    issuerString选填,资产发行账户地址,当null时,仅触发合约
    assetAmountint64选填,资产数量,大小限制[0, max(int64)],当是0时,仅触发合约
    inputString选填,待触发的合约的main()入参
    metadataString选填,备注

ContractInvokeByBUOperation

注意:若目标账户非合约账户且未激活,该操作也可使目标账户激活。

  • 功能

    该操作用于转移BU并触发合约。ContractInvokeByBUOperation继承于BaseOperation。

  • 费用

    FeeLimit要根据合约中执行交易来做添加手续费,首先发起交易手续费目前(2018.07.26)是0.01BU,然后合约中的交易也需要交易发起者添加相应交易的手续费。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    contractAddressString必填,合约账户地址
    buAmountint64选填,资产发行数量,大小限制[0, max(int64)],当0时仅触发合约
    inputString选填,待触发的合约的main()入参
    metadataString选填,备注

LogCreateOperation

  • 功能

    该操作用于记录日志。LogCreateOperation继承于BaseOperation。

  • 费用

    FeeLimit目前(2018.07.26)固定是0.01 BU。

  • 成员

    成员变量类型描述
    sourceAddressString选填,操作源账户地址
    topicString必填,日志主题,长度限制[1, 128]
    datasList必填,日志内容,每个字符串长度限制[1, 1024]
    metadataString选填,备注

账户服务

账户服务主要是账户相关的接口,包括6个接口:checkValid、 getInfo、 getNonce、 getBalancegetAssets、 getMetadata

checkValid

  • 接口说明

    该接口用于检查区块链账户地址的有效性

  • 调用方法

    /**
    * Check the availability of address
    * @param AccountCheckValidRequest $accountCheckValidRequest
    * @return AccountCheckValidResponse
    */
    public function checkValid($accountCheckValidRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待检查的区块链账户地址
  • 响应数据

    参数类型描述
    is_validboolean是否有效
  • 错误码

    异常错误码描述
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $address = "buQemmMwmRQY1JkcU7w3nhruoX5N3j6C29uo";
    $request = new \src\model\request\AccountCheckValidRequest();
    $request->setAddress(address);
    
    // 调用checkValid
    $response = $sdk->getAccountService()->checkValid($request);
    if(0 == $response->error_code) {
        echo $response->result->is_valid . "\n";
    } else {
        echo "error: " . $response->error_desc . "\n";
    }
    

getInfo

  • 接口说明

    该接口用于获取指定的账户信息

  • 调用方法

    /**
    * Get account info
    * @param AccountGetInfoRequest $accountGetInfoRequest
    * @return AccountGetInfoResponse, including address,balance,nonce and privilege
    */
    public function getInfo($accountGetInfoRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的区块链账户地址
  • 响应数据

    参数类型描述
    addressString账户地址
    balanceint64账户余额,单位MO,1 BU = 10^8 MO, 必须大于0
    nonceint64账户交易序列号,必须大于0
    privPriv账户权限
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $accountAddress = "buQemmMwmRQY1JkcU7w3nhruoX5N3j6C29uo";
    $request = new \src\model\request\AccountGetInfoRequest();
    $request->setAddress($accountAddress);
    
    // 调用getInfo接口
    $response =  $sdk->getAccountService()->getInfo($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo "账户信息: " . json_encode($result, JSON_UNESCAPED_UNICODE) . "\n";
    } else {
        echo "error: " . $response->error_desc . "\n";
    }
    

getNonce

  • 接口说明

    该接口用于获取指定账户的nonce值

  • 调用方法

    /**
    * Get account nonce
    * @param AccountGetNonceRequest $accountGetNonceRequest
    * @return AccountGetNonceResponse
    */
    public function getNonce($accountGetNonceRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的区块链账户地址
  • 响应数据

    参数类型描述
    nonceint64账户交易序列号
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $accountAddress = "buQswSaKDACkrFsnP1wcVsLAUzXQsemauEjf";
    $request = new \src\model\request\AccountGetNonceRequest();
    $request->setAddress($accountAddress);
    
    // 调用getNonce接口
    $response = $sdk->getAccountService()->getNonce($request);
    if(0 == $response->error_code){
        echo "账户nonce:" . $response->result->nonce;
    } else {
        echo "error: " . $response->error_desc;
    }
    

getBalance

  • 接口说明

    该接口用于获取指定账户的BU的余额

  • 调用方法

    /**
    * Get account balance of BU
    * @param AccountGetBalanceRequest $accountGetBalanceRequest
    * @return AccountGetBalanceResponse
    */
    public function getBalance($accountGetBalanceRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的区块链账户地址
  • 响应数据

    参数类型描述
    balanceint64BU的余额, 单位MO,1 BU = 10^8 MO
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $accountAddress = "buQswSaKDACkrFsnP1wcVsLAUzXQsemauEjf";
    $request = new \src\model\request\AccountGetBalanceRequest();
    $request->setAddress($accountAddress);
    
    // 调用getBalance接口
    $response = $sdk->getAccountService()->getBalance($request);
    if(0 == $response->error_code){
        $result = $response->result;
        echo "BU余额:" . \src\common\Tools::BU2MO($result->balance) . " BU";
    } else {
        echo "error: " . $response->error_desc;
    }
    

getAssets

  • 接口说明

    该接口用于获取指定账户的所有资产信息

  • 调用方法

    /**
    * Get all assets of an account
    * @param AccountGetAssetsRequest $accountGetAssetsRequest
    * @return AccountGetAssetsResponse, include code, issuer, amount
    */
    public function getAssets;
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的账户地址
  • 响应数据

    参数类型描述
    assetAssetInfo[]账户资产
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    NO_ASSET_ERROR11009The account does not have the asset
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\AccountGetAssetsRequest();
    $request->setAddress("buQsurH1M4rjLkfjzkxR9KXJ6jSu2r9xBNEw");
    
    // 调用getAssets接口
    $response = $sdk->getAccountService()->getAssets($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getMetadata

  • 接口说明

    该接口用于获取指定账户的metadata信息

  • 调用方法

    /**
    * Get the metadata of an account
    * @param AccountGetMetadataRequest $accountGetMetadataRequest
    * @return AccountGetMetadataResponse, include key and value
    */
    public function getMetadata($accountGetMetadataRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的账户地址
    keyString选填,metadata关键字,长度限制[1, 1024]
  • 响应数据

    参数类型描述
    metadataMetadataInfo账户
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    NO_METADATA_ERROR11010The account does not have the metadata
    INVALID_DATAKEY_ERROR11011The length of key must be between 1 and 1024
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $accountAddress = "buQsurH1M4rjLkfjzkxR9KXJ6jSu2r9xBNEw";
    $request = new \src\model\request\AccountGetMetadataRequest();
    $request->setAddress($accountAddress);
    $request->setKey("20180704");
    
    // 调用getMetadata接口
    $response =  $sdk->getAccountService()->getMetadata($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

资产服务

遵循ATP1.0协议,账户服务主要是资产相关的接口,目前有1个接口:getInfo

getInfo

  • 接口说明

    该接口用于获取指定账户的指定资产信息

  • 调用方法

    /**
    * Get details of the specified asset
    * @param  AssetGetInfoRequest $assetGetInfoRequest
    * @return AssetGetInfoResponse
    */
    function getInfo($assetGetInfoRequest);
    
  • 请求参数

    参数类型描述
    addressString必填,待查询的账户地址
    codeString必填,资产编码,长度限制[1, 64]
    issuerString必填,资产发行账户地址
  • 响应数据

    参数类型描述
    assetAssetInfo[]账户资产
  • 错误码

    异常错误码描述
    INVALID_ADDRESS_ERROR11006Invalid address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    INVALID_ASSET_CODE_ERROR11023The length of asset code must be between 1 and 64
    INVALID_ISSUER_ADDRESS_ERROR11027Invalid issuer address
    NO_ASSET_ERROR11009The account does not have this token
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\AssetGetInfoRequest();
    $request->setAddress("buQsurH1M4rjLkfjzkxR9KXJ6jSu2r9xBNEw");
    $request->setIssuer("buQBjJD1BSJ7nzAbzdTenAhpFjmxRVEEtmxH");
    $request->setCode("HNC");
    
    // 调用getInfo消息
    $response = $sdk->getAssetService()->getInfo($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

合约服务

合约服务主要是合约相关的接口,目前有4个接口:checkValidgetInfogetAddresscall

checkValid

  • 接口说明

    该接口用于检测合约账户的有效性

  • 调用方法

    /**
    * Check the availability of a contract
    * @param  ContractCheckValidRequest $contractCheckValidRequest
    * @return ContractCheckValidResponse
    */
    function checkValid($contractCheckValidRequest);
    
  • 请求参数

    参数类型描述
    contractAddressString待检测的合约账户地址
  • 响应数据

    参数类型描述
    isValidBoolean是否有效
  • 错误码

    异常错误码描述
    INVALID_CONTRACTADDRESS_ERROR11037Invalid contract address
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\ContractCheckValidRequest();
    $request->setContractAddress("buQfnVYgXuMo3rvCEpKA6SfRrDpaz8D8A9Ea");
    
    // 调用checkValid接口
    $response = $sdk->getContractService()->checkValid($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo result->is_valid;
    } else {
        echo "error: " . $response->error_desc;
    }
    

getInfo

  • 接口说明

    该接口用于查询合约代码

  • 调用方法

    /**
    * Get the details of contract, include type and payload
    * @param ContractGetInfoRequest $contractGetInfoRequest
    * @return ContractGetInfoResponse
    */
    function getInfo($contractGetInfoRequest);
    
  • 请求参数

    参数类型描述
    contractAddressString待查询的合约账户地址
  • 响应数据

    参数类型描述
    contractContractInfo合约信息
  • 错误码

    异常错误码描述
    INVALID_CONTRACTADDRESS_ERROR11037Invalid contract address
    CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR11038contractAddress is not a contract account
    NO_SUCH_TOKEN_ERROR11030No such token
    GET_TOKEN_INFO_ERROR11066Failed to get token info
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\ContractGetInfoRequest();
    $request->setContractAddress("buQfnVYgXuMo3rvCEpKA6SfRrDpaz8D8A9Ea");
    
    // 调用getInfo接口
    $response = $sdk->getContractService()->getInfo($request);
    if ($response->error_code == 0) {
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getAddress

  • 接口说明

该接口用于查询合约地址

  • 调用方法

    /**
    * Get the address of a contract account
    * @param  ContractGetAddressRequest $contractGetAddressRequest
    * @return ContractGetAddressResponse
    */
    function getAddress($contractGetAddressRequest)
    
  • 请求参数

    参数类型描述
    hashString创建合约交易的hash
  • 响应数据

    参数类型描述
    contractAddressListList<ContractAddressInfo>合约地址列表
  • 错误码

    异常错误码描述
    INVALID_HASH_ERROR11055Invalid transaction hash
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\ContractGetAddressRequest();
    $request->setHash("44246c5ba1b8b835a5cbc29bdc9454cdb9a9d049870e41227f2dcfbcf7a07689");
    
    // 调用getAddress接口
    $response = $sdk->getContractService()->getAddress($request);
    if ($response->error_code == 0) {
    echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else {
    echo "error: " . $response->error_desc;
    }
    

call

  • 接口说明

    该接口用于调试合约代码

  • 调用方法

    /**
    * Call contract for free
    * @param  ContractCallRequest $contractCallRequest
    * @return ContractCallResponse
    */
    function call($contractCallRequest);
    
  • 请求参数

    参数类型描述
    sourceAddressString选填,合约触发账户地址
    contractAddressString选填,合约账户地址,与code不能同时为空
    codeString选填,合约代码,与contractAddress不能同时为空,长度限制[1, 64]
    inputString选填,合约入参
    contractBalanceString选填,赋予合约的初始 BU 余额, 单位MO,1 BU = 10^8 MO, 大小限制[1, max(int64)]
    optTypeInteger必填,0: 调用合约的读写接口 init, 1: 调用合约的读写接口 main, 2 :调用只读接口 query
    feeLimitint64交易要求的最低手续费, 大小限制[1, max(int64)]
    gasPriceint64交易燃料单价,大小限制[1000, max(int64)]
  • 响应数据

    参数类型描述
    logsJSONObject日志信息
    queryRetsJSONArray查询结果集
    statContractStat合约资源占用信息
    txsTransactionEnvs[]交易集
  • 错误码

    异常错误码描述
    INVALID_SOURCEADDRESS_ERROR11002Invalid sourceAddress
    INVALID_CONTRACTADDRESS_ERROR11037Invalid contract address
    CONTRACTADDRESS_CODE_BOTH_NULL_ERROR11063ContractAddress and code cannot be empty at the same time
    INVALID_OPTTYPE_ERROR11064OptType must be between 0 and 2
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_CONTRACT_BALANCE_ERROR11044The contractBalance must be between 1 and max(int64)
    INVALID_GASPRICE_ERROR11049GasPrice must be between 1000 and max(int64)
    INVALID_REQUEST_ERROR17004Request is invalid
    INPUT_NOT_STRING_ERROR17002Input must be a string
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\ContractCallRequest();
    $request->setCode("\"use strict\";log(undefined);function query() { getBalance(thisAddress); }");
    $request->setFeeLimit(1000000000);
    $request->setOptType(2);
    
    // 调用call接口
    $response = $sdk->getContractService()->call($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

区块服务

区块服务主要是区块相关的接口,目前有11个接口:getNumbercheckStatusgetTransactionsgetInfogetLatestInfogetValidatorsgetLatestValidatorsgetRewardgetLatestRewardgetFeesgetLatestFees

getNumber

  • 接口说明

    该接口用于查询最新的区块高度

  • 调用方法

    /**
    * Get the latest block number
    * @return BlockGetNumberResponse
    */
    function getNumber()
    
  • 响应数据

    参数类型描述
    blockNumberint64最新的区块高度,对应底层字段seq
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用getNumber接口
    $response = $sdk->getBlockService()->getNumber();
    if(0 == $response->error_code){
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    }else{
        echo "error: " . $response->error_desc;
    }
    

checkStatus

  • 接口说明

    该接口用于检查本地节点区块是否同步完成

  • 调用方法

    /**
    * Check the status of block synchronization
    * @return BlockCheckStatusResponse
    */
    public function checkStatus()
    
  • 响应数据

    参数类型描述
    isSynchronousBoolean区块是否同步
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用checkStatus
    $response = $sdk->getBlockService()->checkStatus();
    if(0 == $response->error_code){
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    }else{
        echo "error: " . $response->error_desc;
    }
    

getTransactions

  • 接口说明

    该接口用于查询指定区块高度下的所有交易

  • 调用方法

    /**
    * Get the transactions of specific block
    * @param BlockGetTransactionsRequest $blockGetTransactionsRequest
    * @return BlockGetTransactionsResponse
    */
    function getTransactions($blockGetTransactionsRequest)
    
  • 请求参数

    参数类型描述
    blockNumberint64必填,待查询的区块高度,必须大于0
  • 响应数据

    参数类型描述
    totalCountint64返回的总交易数
    transactionsTransactionHistory[]交易内容
  • 错误码

    异常错误码描述
    INVALID_BLOCKNUMBER_ERROR11060BlockNumber must bigger than 0
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $blockNumber = 617247;// 第617247区块
    $request = new \src\model\request\BlockGetTransactionsRequest();
    $request->setBlockNumber($blockNumber);
    
    // 调用getTransactions接口
    $response = $sdk->getBlockService()->getTransactions($request);
    if(0 == $response->error_code){
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    }else{
        echo "error: " . $response->error_desc;
    }
    

getInfo

  • 接口说明

    该接口用于获取区块信息

  • 调用方法

    /**
    * Get the information of specific block
    * @param BlockGetInfoRequest $blockGetInfoRequest
    * @return BlockGetInfoResponse
    */
    function getInfo($blockGetInfoRequest)
    
  • 请求参数

    参数类型描述
    blockNumberint64必填,待查询的区块高度
  • 响应数据

    参数类型描述
    closeTimeint64区块关闭时间
    numberint64区块高度
    txCountint64交易总量
    versionString区块版本
  • 错误码

    异常错误码描述
    INVALID_BLOCKNUMBER_ERROR11060BlockNumber must bigger than 0
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\BlockGetInfoRequest();
    $request->setBlockNumber(629743);
    
    // 调用getInfo接口
    $response = $sdk->getBlockService()->getInfo($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getLatestInfo

  • 接口说明

    该接口用于获取最新区块信息

  • 调用方法

    /**
    * Get the latest information of block
    * @return BlockGetLatestInfoResponse
    */
    function getLatestInfo()
    
  • 响应数据

    参数类型描述
    closeTimeint64区块关闭时间
    numberint64区块高度,对应底层字段seq
    txCountint64交易总量
    versionString区块版本
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用getLatestInfo接口
    $response = $sdk->getBlockService()->getLatestInfo();
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getValidators

  • 接口说明

    该接口用于获取指定区块中所有验证节点数

  • 调用方法

    /**
    * Get the validators of specific block
    * @param  BlockGetValidatorsRequest $blockGetValidatorsRequest
    * @return BlockGetValidatorsResponse
    */
    function getValidators($blockGetValidatorsRequest)
    
  • 请求参数

    参数类型描述
    blockNumberint64必填,待查询的区块高度,必须大于0
  • 响应数据

    参数类型描述
    validatorsValidatorInfo[]验证节点列表
  • 错误码

    异常错误码描述
    INVALID_BLOCKNUMBER_ERROR11060BlockNumber must bigger than 0
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\BlockGetValidatorsRequest();
    $request->setBlockNumber(629743);
    
    // 调用getValidators接口
    $response = $sdk->getBlockService()->getValidators($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getLatestValidators

  • 接口说明

    该接口用于获取最新区块中所有验证节点数

  • 调用方法

    /**
    * Get the latest validators of block
    * @return BlockGetLatestValidatorsResponse
    */
    function getLatestValidators()
    
  • 响应数据

    参数类型描述
    validatorsValidatorInfo[]验证节点列表
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用getLatestValidators接口
    $response = $sdk->getBlockService()->getLatestValidators();
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getReward

  • 接口说明

    该接口用于获取指定区块中的区块奖励和验证节点奖励

  • 调用方法

    /**
    * Get the reward of specific block
    * @param  BlockGetRewardRequest $blockGetRewardRequest
    * @return BlockGetRewardResponse
    */
    function GetReward($blockGetRewardRequest)
    
  • 请求参数

    参数类型描述
    blockNumberint64必填,待查询的区块高度,必须大于0
  • 响应数据

    参数类型描述
    blockRewardint64区块奖励数
    validatorsRewardValidatorReward[]验证节点奖励情况
  • 错误码

    异常错误码描述
    INVALID_BLOCKNUMBER_ERROR11060BlockNumber must bigger than 0
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\BlockGetRewardRequest();
    $request->setBlockNumber(629743);
    
    // 调用getReward接口
    $response = $sdk->getBlockService()->getReward($request);
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getLatestReward

  • 接口说明

    获取最新区块中的区块奖励和验证节点奖励

  • 调用方法

    /**
    * Get the latest reward of block
    * @return BlockGetLatestRewardResponse
    */
    function GetLatestReward()
    
  • 响应数据

    参数类型描述
    blockRewardint64区块奖励数
    validatorsRewardValidatorReward[]验证节点奖励情况
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用getLatestReward接口
    $response = $sdk->getBlockService()->getLatestReward();
    if ($response->error_code == 0) {
        $result = $response->result;
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getFees

  • 接口说明

    获取指定区块中的账户最低资产限制和燃料单价

  • 调用方法

    /**
    * Get the fees of specific block
    * @param  BlockGetFeesRequest $blockGetFeesRequest
    * @return BlockGetFeesResponse
    */
    function getFees($blockGetFeesRequest)
    
  • 请求参数

    参数类型描述
    blockNumberint64必填,待查询的区块高度,必须大于0
  • 响应数据

    参数类型描述
    feesFees费用
  • 错误码

    异常错误码描述
    INVALID_BLOCKNUMBER_ERROR11060BlockNumber must bigger than 0
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
    INVALID_REQUEST_ERROR17004Request is invalid
  • 示例

    // 初始化请求参数
    $request = new \src\model\request\BlockGetFeesRequest();
    $request->setBlockNumber(629743L);
    
    // 调用getFees接口
    $response = $sdk->getBlockService()->getFees($request);
    if ($response->error_code == 0) {
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

getLatestFees

  • 接口说明

    该接口用于获取最新区块中的账户最低资产限制和燃料单价

  • 调用方法

    /**
    * Get the latest fees of block
    * @return BlockGetLatestFeesResponse
    */
    function getLatestFees()
    
  • 响应数据

    参数类型描述
    feesFees费用
  • 错误码

    异常错误码描述
    CONNECTNETWORK_ERROR11007Failed to connect to the network
    SYSTEM_ERROR20000System error
  • 示例

    // 调用getLatestFees接口
    $response = $sdk->getBlockService()->getLatestFees();
    if ($response->error_code == 0) {
        echo json_encode($response->result, JSON_UNESCAPED_UNICODE);
    } else {
        echo "error: " . $response->error_desc;
    }
    

数据对象

Priv

成员类型描述
masterWeightint64账户自身权重,大小限制[0, max(uint32)]
signersSigner[]签名者权重列表
thresholdThreshold门限

Signer

成员类型描述
addressString签名者区块链账户地址
weightint64签名者权重,大小限制[0, max(uint32)]

Threshold

成员类型描述
txThresholdint64交易默认门限,大小限制[0, max(int64)]
typeThresholdsTypeThreshold[]不同类型交易的门限

TypeThreshold

成员类型描述
typeint64操作类型,必须大于0
thresholdint64门限值,大小限制[0, max(int64)]

AssetInfo

成员类型描述
keyKey资产惟一标识
assetAmountint64资产数量

Key

成员类型描述
codeString资产编码
issuerString资产发行账户地址

MetadataInfo

成员类型描述
keyStringmetadata的关键词
valueStringmetadata的内容
versionint64metadata的版本

ContractInfo

成员类型描述
typeInteger合约类型,默认0
payloadString合约代码

ContractAddressInfo

成员类型描述
contractAddressString合约地址
operationIndexInteger所在操作的下标

ContractStat

成员类型描述
applyTimeint64接收时间
memoryUsageint64内存占用量
stackUsageint64堆栈占用量
stepint64几步完成

TransactionEnvs

成员类型描述
transactionEnvTransactionEnv交易

TransactionEnv

成员类型描述
transactionTransactionInfo交易内容
triggerContractTrigger合约触发者

TransactionInfo

成员类型描述
sourceAddressString交易发起的源账户地址
feeLimitint64交易要求的最低费用
gasPriceint64交易燃料单价
nonceint64交易序列号
operationsOperation[]操作列表

ContractTrigger

成员类型描述
transactionTriggerTransaction触发交易

Operation

成员类型描述
typeInteger操作类型
sourceAddressString操作发起源账户地址
metadataString备注
createAccountOperationCreateAccount创建账户操作
issueAssetOperationIssueAsset发行资产操作
payAssetOperationPayAsset转移资产操作
payCoinOperationPayCoin发送BU操作
setMetadataOperationSetMetadata设置metadata操作
setPrivilegeOperationSetPrivilege设置账户权限操作
logOperationLog记录日志

TriggerTransaction

成员类型描述
hashString交易hash

OperationCreateAccount

成员类型描述
destAddressString目标账户地址
contractContract合约信息
privPriv账户权限
metadataMetadataInfo[]账户
initBalanceint64账户资产, 单位MO,1 BU = 10^8 MO
initInputString合约init函数的入参

Contract

成员类型描述
typeInteger合约的语种,默认不赋值
payloadString对应语种的合约代码

MetadataInfo

成员类型描述
keyStringmetadata的关键词
valueStringmetadata的内容
versionint64metadata的版本

OperationIssueAsset

成员类型描述
codeString资产编码
assetAmountint64资产数量

OperationPayAsset

成员类型描述
destAddressString待转移的目标账户地址
assetAssetInfo账户资产
inputString合约main函数入参

OperationPayCoin

成员类型描述
destAddressString待转移的目标账户地址
buAmountint64待转移的BU数量
inputString合约main函数入参

OperationSetMetadata

成员类型描述
keyStringmetadata的关键词
valueStringmetadata的内容
versionint64metadata的版本
deleteFlagboolean是否删除metadata

OperationSetPrivilege

成员类型描述
masterWeightString账户自身权重,大小限制[0, max(uint32)]
signersSigner[]签名者权重列表
txThresholdString交易门限,大小限制[0, max(int64)]
typeThresholdTypeThreshold指定类型交易门限

OperationLog

成员类型描述
topicString日志主题
dataString[]日志内容

TestTx

成员类型描述
transactionEnvTestTransactionFees评估交易费用

TestTransactionFees

成员类型描述
transactionFeesTransactionFees交易费用

TransactionFees

成员类型描述
feeLimitint64交易要求的最低费用
gasPriceint64交易燃料单价

Signature

成员类型描述
signDataint64签名后数据
publicKeyint64公钥

TransactionHistory

成员类型描述
actualFeeString交易实际费用
closeTimeint64交易关闭时间
errorCodeint64交易错误码
errorDescString交易描述
hashString交易hash
ledgerSeqint64区块序列号
transactionTransactionInfo交易内容列表
signaturesSignature[]签名列表
txSizeint64交易大小

ValidatorInfo

成员类型描述
addressString共识节点地址
plegeCoinAmountint64验证节点押金

ValidatorReward

成员类型描述
validatorString验证节点地址
rewardint64验证节点奖励

Fees

成员类型描述
baseReserveint64账户最低资产限制
gasPriceint64交易燃料单价,单位MO,1 BU = 10^8 MO

错误码

异常错误码描述
ACCOUNT_CREATE_ERROR11001Failed to create the account
INVALID_SOURCEADDRESS_ERROR11002Invalid sourceAddress
INVALID_DESTADDRESS_ERROR11003Invalid destAddress
INVALID_INITBALANCE_ERROR11004InitBalance must be between 1 and max(int64)
SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR11005SourceAddress cannot be equal to destAddress
INVALID_ADDRESS_ERROR11006Invalid address
CONNECTNETWORK_ERROR11007Failed to connect to the network
INVALID_ISSUE_AMOUNT_ERROR11008Amount of the token to be issued must be between 1 and max(int64)
NO_ASSET_ERROR11009The account does not have the asset
NO_METADATA_ERROR11010The account does not have the metadata
INVALID_DATAKEY_ERROR11011The length of key must be between 1 and 1024`
INVALID_DATAVALUE_ERROR11012The length of value must be between 0 and 256000
INVALID_DATAVERSION_ERROR11013The version must be equal to or bigger than 0
INVALID_MASTERWEIGHT_ERROR11015MasterWeight must be between 0 and max(uint32)
INVALID_SIGNER_ADDRESS_ERROR11016Invalid signer address
INVALID_SIGNER_WEIGHT_ERROR11017Signer weight must be between 0 and max(uint32)
INVALID_TX_THRESHOLD_ERROR11018TxThreshold must be between 0 and max(int64)
INVALID_OPERATION_TYPE_ERROR11019Operation type must be between 1 and 100
INVALID_TYPE_THRESHOLD_ERROR11020TypeThreshold must be between 0 and max(int64)
INVALID_ASSET_CODE_ERROR11023The length of key must be between 1 and 64
INVALID_ASSET_AMOUNT_ERROR11024AssetAmount must be between 0 and max(int64)
INVALID_BU_AMOUNT_ERROR11026BuAmount must be between 0 and max(int64)
INVALID_ISSUER_ADDRESS_ERROR11027Invalid issuer address
NO_SUCH_TOKEN_ERROR11030No such token
INVALID_TOKEN_NAME_ERROR11031The length of token name must be between 1 and 1024
INVALID_TOKEN_SIMBOL_ERROR11032The length of symbol must be between 1 and 1024
INVALID_TOKEN_DECIMALS_ERROR11033Decimals must be between 0 and 8
INVALID_TOKEN_TOTALSUPPLY_ERROR11034TotalSupply must be between 1 and max(int64)
INVALID_TOKENOWNER_ERRPR11035Invalid token owner
INVALID_CONTRACTADDRESS_ERROR11037Invalid contract address
CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR11038contractAddress is not a contract account
INVALID_TOKEN_AMOUNT_ERROR11039TokenAmount must be between 1 and max(int64)
SOURCEADDRESS_EQUAL_CONTRACTADDRESS_ERROR11040SourceAddress cannot be equal to contractAddress
INVALID_FROMADDRESS_ERROR11041Invalid fromAddress
FROMADDRESS_EQUAL_DESTADDRESS_ERROR11042FromAddress cannot be equal to destAddress
INVALID_SPENDER_ERROR11043Invalid spender
PAYLOAD_EMPTY_ERROR11044Payload cannot be empty
INVALID_LOG_TOPIC_ERROR11045The length of a log topic must be between 1 and 128
INVALID_LOG_DATA_ERROR11046The length of one piece of log data must be between 1 and1024
INVALID_CONTRACT_TYPE_ERROR11047Invalid contract type
INVALID_NONCE_ERROR11048Nonce must be between 1 and max(int64)
INVALID_GASPRICE_ERROR11049GasPrice must be between 1000 and max(int64)
INVALID_FEELIMIT_ERROR11050FeeLimit must be between 1 and max(int64)
OPERATIONS_EMPTY_ERROR11051Operations cannot be empty
INVALID_CEILLEDGERSEQ_ERROR11052CeilLedgerSeq must be equal to or bigger than 0
OPERATIONS_ONE_ERROR11053One of the operations cannot be resolved
INVALID_SIGNATURENUMBER_ERROR11054SignagureNumber must be between 1 and max(uint32)
INVALID_HASH_ERROR11055Invalid transaction hash
INVALID_BLOB_ERROR11056Invalid blob
PRIVATEKEY_NULL_ERROR11057PrivateKeys cannot be empty
PRIVATEKEY_ONE_ERROR11058One of privateKeys is invalid
SIGNDATA_NULL_ERROR11059SignData cannot be empty
INVALID_BLOCKNUMBER_ERROR11060BlockNumber must be bigger than 0
PUBLICKEY_NULL_ERROR11061PublicKey cannot be empty
URL_EMPTY_ERROR11062Url cannot be empty
CONTRACTADDRESS_CODE_BOTH_NULL_ERROR11063ContractAddress and code cannot be empty at the same time
INVALID_OPTTYPE_ERROR11064OptType must be between 0 and 2
GET_ALLOWANCE_ERROR11065Failed to get allowance
GET_TOKEN_INFO_ERROR11066Failed to get token info
SIGNATURE_EMPTY_ERROR11067The signatures cannot be empty
REQUEST_NULL_ERROR12001Request parameter cannot be null
CONNECTN_BLOCKCHAIN_ERROR19999Failed to connect to the blockchain
SYSTEM_ERROR20000System error
METADATA_NOT_STRING_ERROR17001Metadata must be a string
INPUT_NOT_STRING_ERROR17002Input must be a string
INIT_INPUT_NOT_STRING_ERROR17003InitInput must be a string
INVALID_REQUEST_ERROR17004Request is invalid
INVALID_DELETE_FLAG_ERROR17005The deleteFlag is invalid
SIGNERS_NOT_ARRAY_ERROR17006The signers should be an array
INVALID_SIGNER_ERROR17007The signer is invalid
TYPE_THRESHOLDS_NOT_ARRAY_ERROR17008The typeThresholds should be an array

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web3.0前沿技术研究者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值