文档中心

文档中心

  • English

›SDK

介绍

  • 概述
  • 优势

节点部署

  • 概述和系统要求
  • 接入体验链
  • 搭建私链
  • 运维
  • 常见问题

API

  • 概述
  • HTTP
  • Websocket
  • Keypair

SDK

  • JAVA
  • Nodejs
  • GO
  • PHP
  • IOS
  • 隐私交易 JNI

场景示例

  • 资产发行
  • 存证
  • 智能合约资产
  • 隐私交易

智能合约

  • 介绍
  • 语法说明

术语

  • 术语

BubiChain IOS SDK

概述

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

环境要求

环境依赖ios 8.0或更高系统版本。

安装

  1. 由布比官方提供 framework 包。
  2. 将libs目录下的sdk_ios.framework拖到项目中,并选择"Copy items if needed"。
  3. 在"Build Phases"的"Link Binary With Libraries"中添加"libc++.tbd"。
  4. 在""Build Setting"的"Other Linker Flags"添加"-ObjC"。
  5. 在项目中添加头文件,命令是"#import <sdk_ios/sdk_ios.h>"。

请求与响应数据格式

请求参数

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

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

@interface AccountGetInfoRequest : NSObject {
@private
    NSString *_address;
}
-(void)setAddress:(NSString *)address;
-(NSString *)getAddress;

响应数据

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

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

@interface AccountGetNonceResponse : NSObject
@property (nonatomic, assign) int32_t errorCode;
@property (nonatomic, copy) NSString *errorDesc;
@property (nonatomic, strong) AccountGetNonceResult *result;
@end

说明:

  1. errorCode: 错误码。0表示无错误,大于0表示有错误
  2. errorDesc: 错误描述。
  3. result: 返回结果。一个结构体,其类名是[服务名][方法名]Result,其成员是各个接口返回值的成员,例如:账户服务下的getNonce接口的结果类名是AccountGetNonceResult,成员有nonce, 完整结构如下:
@interface AccountGetNonceResult : NSObject
@property (nonatomic, assign) int64_t nonce;
@end

快速使用

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

生成SDK实例

调用SDK的接口getInstance来实现

简单配置

调用如下:

NSString *url = @"http://seed1-node.bubi.cn";
SDK *sdk = [[SDK sharedInstance] setUrl: url];

超时配置

调用如下:

NSString *url = @"http://seed1-node.bubi.cn";
SDKConfigure *sdkConfigure = [SDKConfigure new];
[sdkConfigure setTimeOut: 60];

SDK *sdk = [[[SDK sharedInstance] setUrl: url] setConfigure: sdkConfigure];

生成公私钥地址

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

AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
AccountCreateResponse *response = [accountService create];
if (response.errorCode == 0) {
    NSLog(@"%@", [response.result yy_modelToJSONString]);
} else {
    NSLog(@"%@", response.errorDesc);
}

有效性校验

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

// 初始化请求参数
AccountService *accountService = [sdk getAccountService];
AccountCheckValidRequest *request = [AccountCheckValidRequest new];
[request setAddress:@"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C"];

// 调用checkValid接口
AccountCheckValidResponse *response = [accountService checkValid: nil];
if (response.errorCode == 0) {
    NSLog(@"%@", [response.result yy_modelToJSONString]);
} else {
    NSLog(@"%@", response.errorDesc);
}

查询

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

// 初始化请求参数
NSString *address = @"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C";
AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
AccountGetInfoRequest *request = [AccountGetInfoRequest new];
[request setAddress : address];

// 调用getInfo接口
AccountGetInfoResponse *response = [accountService getInfo : request];
if (response.errorCode == 0) {
    NSLog(@"%@", [response.result yy_modelToJSONString]);
} else {
    NSLog(@"%@", response.errorDesc);
}

广播交易

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

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

获取账户nonce值

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

// 初始化请求参数
NSString *address = @"adxSa4oENoQCc66JRouZu1rKu4RWjgS69YD4S";
AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
AccountGetNonceRequest * request = [AccountGetNonceRequest new];
[request setAddress : address];

// 调用getNonce接口
AccountGetNonceResponse *response = [accountService getNonce : request];
if (response.errorCode == 0) {
    NSLog(@"%@", [response.result yy_modelToJSONString]);
} else {
    NSLog(@"%@", response.errorDesc);
}

构建操作

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

// 初始化变量
NSString *sourceAddress = @"adxSa4oENoQCc66JRouZu1rKu4RWjgS69YD4S";
NSString *destAddress = @"adxSgTxU1awVzNUeR8xcnd3K75XKU8ziNHcWW";
int64_t amount = 1000000;

// 构建GasSendOperation
GasSendOperation *operation = [GasSendOperation new];
[operation setSourceAddress: sourceAddress];
[operation setDestAddress: destAddress];
[operation setAmount: amount];

序列化交易

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

// 初始化变量
int64_t gasPrice = 1000;
int64_t feeLimit = 1000000;

// 初始化请求参数
TransactionBuildBlobRequest *buildBlobRequest = [TransactionBuildBlobRequest new];
[buildBlobRequest setSourceAddress : sourceAddress];
[buildBlobRequest setNonce : nonce];
[buildBlobRequest setGasPrice : gasPrice];
[buildBlobRequest setFeeLimit : feeLimit];
[buildBlobRequest addOperation : operation];

// 调用buildBlob接口
TransactionService *transactionServer = [sdk getTransactionService];
TransactionBuildBlobResponse *buildBlobResponse = [transactionServer buildBlob : buildBlobRequest];
if (buildBlobResponse.errorCode == 0) {
    NSLog(@"blob: %@, hash: %@", buildBlobResponse.result.transactionBlob, buildBlobResponse.result.transactionHash);
} else {
    NSLog(@"error: %@", buildBlobResponse.errorDesc);
    return;
}

签名交易

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

// 初始化请求参数
NSString *privateKey = @"privbwAQyE2vWwzt9NuC8vecqpZm7DS8kfiMPsKPcrTatUkmkxkVhfaf";
TransactionSignRequest *signRequest = [TransactionSignRequest new];
[signRequest setBlob : buildBlobResponse.result.transactionBlob];
[signRequest addPrivateKey : privateKey];

// 调用sign接口
TransactionSignResponse * signResponse = [transactionServer sign : signRequest];
if (signResponse.errorCode == 0) {
    NSLog(@"sign response: %@", [signResponse yy_modelToJSONString]);
} else {
    NSLog(@"error: %@", signResponse.errorDesc);
    return;
}

提交交易

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

// 初始化请求参数
TransactionSubmitRequest *submitRequest = [TransactionSubmitRequest new];
[submitRequest setTransactionBlob : buildBlobResponse.result.transactionBlob];
[submitRequest setSignatures : [signResponse.result.signatures copy]];

// 调用submit接口
TransactionSubmitResponse *submitResponse = [transactionServer submit : submitRequest];
if (submitResponse.errorCode == 0) {
    NSLog(@"submit response: %@", [submitResponse yy_modelToJSONString]);
} else {
    NSLog(@"error: %@", submitResponse.errorDesc);
}

具体方法

方法服务包括账户服务、资产服务、合约服务、交易服务、区块服务。

交易服务

交易服务主要是交易相关的接口,目前有5个接口:buildBlob、evaluateFee、sign、submit、getInfo。

buildBlob

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

  • 接口说明

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

  • 调用方法

    TransactionBuildBlobResponse *) buildBlob : (TransactionBuildBlobRequest *) transactionBuildBlobRequest;

  • 请求参数

    参数类型描述
    sourceAddressNSString*必填,发起该操作的源账户地址
    nonceint64_t必填,待发起的交易序列号,函数里+1,大小限制[1, max(int64)]
    gasPriceint64_t必填,交易费用单价,按字节收费,单位UGas,1 Gas = 10^8 UGas,大小限制[1000, max(int64)]
    feeLimitint64_t必填,交易要求的最低的手续费,单位UGas,1 Gas = 10^8 UGas,大小限制[1, max(int64)]
    operationNSArray<BaseOperation *> *必填,待提交的操作列表,不能为空
    ceilLedgerSeqint64_t选填,距离当前区块高度指定差值的区块内执行的限制,当区块超出当时区块高度与所设差值的和后,交易执行失败。必须大于等于0,是0时不限制
    metadataNSString*选填,备注
  • 响应数据

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

    异常错误码描述
    INVALID_SOURCGasDDRESS_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)
    SOURCGasDDRESS_EQUAL_DESTADDRESS_ERROR11005SourceAddress cannot be equal to destAddress
    INVALID_ISSUE_AMOUNT_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 greater 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 asset code must be between 1 and 64
    INVALID_ASSET_AMOUNT_ERROR11024AssetAmount must be between 0 and max(int64)
    INVALID_GAS_AMOUNT_ERROR11026GasAmount 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)
    SOURCGasDDRESS_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 greater than 0
    OPERATIONS_ONE_ERROR11053One of the operations cannot be resolved
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
  • 示例

    // 初始化变量
    NSString* senderAddresss = @"adxSYQ8iMyZ7Dkj1oX1kjGMV55WXvoPKcLEK3";
    NSString* destAddress = @"adxSgTxU1awVzNUeR8xcnd3K75XKU8ziNHcWW";
    int64_t eaAmount = [Tools ToUGas : 10.9];
    int64_t gasPrice = 1000;
    int64_t feeLimit = [Tools ToUGas : 0.01];
    int64_t nonce = 1;
    
    // 构建sendGas操作
    GasSendOperation *operation = [GasSendOperation new];
    [operation setSourceAddress: senderAddresss];
    [operation setDestAddress: destAddress];
    [operation setAmount: eaAmount];
    
    // 初始化请求参数
    TransactionBuildBlobRequest *buildBlobRequest = [TransactionBuildBlobRequest new];
    [buildBlobRequest setSourceAddress : senderAddresss];
    [buildBlobRequest setNonce : nonce];
    [buildBlobRequest setGasPrice : gasPrice];
    [buildBlobRequest setFeeLimit : feeLimit];
    [buildBlobRequest addOperation : operation];
    
    // 调用buildBlob接口
    TransactionService *transactionServer = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getTransactionService];
    TransactionBuildBlobResponse *buildBlobResponse = [transactionServer buildBlob : buildBlobRequest];
    if (buildBlobResponse.errorCode == 0) {
        NSLog(@"blob: %@, hash: %@", buildBlobResponse.result.transactionBlob, buildBlobResponse.result.transactionHash);
    } else {
        NSLog(@"error: %@", buildBlobResponse.errorDesc);
        return;
    }
    

evaluateFee

  • 接口说明

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

  • 调用方法

    TransactionEvaluateFeeResponse *) evaluateFee : (TransactionEvaluateFeeRequest *) transactionEvaluateFeeRequest;

  • 请求参数

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

    参数类型描述
    txsNSArray<TestTx *> *评估交易集
  • 错误码

    异常错误码描述
    INVALID_SOURCGasDDRESS_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(int32)
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
  • 示例

    // 初始化变量
    NSString* senderAddresss = @"adxSa4oENoQCc66JRouZu1rKu4RWjgS69YD4S";
    NSString* destAddress = @"adxSYQ8iMyZ7Dkj1oX1kjGMV55WXvoPKcLEK3";
    int64_t eaAmount = [Tools ToUGas : 10.9];
    int64_t gasPrice = 1000;
    int64_t feeLimit = [Tools ToUGas : 0.01];
    int64_t nonce = 1;
    
    // 构建sendGas操作
    GasSendOperation *operation = [GasSendOperation new];
    [operation setSourceAddress: senderAddresss];
    [operation setDestAddress: destAddress];
    [operation setAmount: eaAmount];
    
    // 初始化评估交易请求参数
    TransactionEvaluateFeeRequest *request = [TransactionEvaluateFeeRequest new];
    [request addOperation : gasSendOperation];
    [request setSourceAddress : senderAddresss];
    [request setNonce : nonce];
    [request setSignatureNumber : 1];
    [request setMetadata : @"evaluate fees"];
    
    // 调用evaluateFee接口
    TransactionService *transactionServer = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getTransactionService];
    TransactionEvaluateFeeResponse* response = [transactionServer evaluateFee : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

sign

  • 接口说明

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

  • 调用方法

    TransactionSignResponse *) sign : (TransactionSignRequest *) transactionSignRequest;

  • 请求参数

    参数类型描述
    blobNSString*必填,待签名的交易Blob
    privateKeysNSArray<NSString *> *必填,私钥列表
  • 响应数据

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

    异常错误码描述
    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
  • 示例

    // 初始化请求参数
    NSString* issuePrivateKey = @"privbyQCRp7DLqKtRFCqKQJr81TurTqG6UKXMMtGAmPG3abcM9XHjWvq";
    NSString* transactionBlob = @"0A246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370102118C0843D20E8073A56080712246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370522C0A24627551426A4A443142534A376E7A41627A6454656E416870466A6D7852564545746D78481080A9E08704";
    TransactionSignRequest *signRequest = [TransactionSignRequest new];
    [signRequest setBlob : transactionBlob];
    [signRequest addPrivateKey : issuePrivateKey];
    
    // 调用sign接口
    TransactionService *transactionServer = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getTransactionService];
    TransactionSignResponse * signResponse = [transactionServer sign : signRequest];
    if (signResponse.errorCode == 0) {
        NSLog(@"sign response: %@", [signResponse yy_modelToJSONString]);
    } else {
        NSLog(@"error: %@", signResponse.errorDesc);
        return;
    }
    

submit

  • 接口说明

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

  • 调用方法

    TransactionSubmitResponse *) submit : (TransactionSubmitRequest *) transactionSubmitRequest;

  • 请求参数

    参数类型描述
    blobNSString*必填,交易blob
    signatureSignatureInfo必填,签名列表
  • 响应数据

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

    异常错误码描述
    INVALID_BLOB_ERROR11056Invalid blob
    SIGNATURE_EMPTY_ERROR11067The signatures cannot be empty
    REQUEST_NULL_ERROR12001Request parameter cannot be null
    SYSTEM_ERROR20000System error
  • 示例

    // 初始化请求参数
    NSString* transactionBlob = @"0A246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370102118C0843D20E8073A56080712246275516E6E5545425245773268423670574847507A77616E5837643238786B364B566370522C0A24627551426A4A443142534A376E7A41627A6454656E416870466A6D7852564545746D78481080A9E08704";
    SignatureInfo *signature = [SignatureInfo new];
    signature.signData = @"D2B5E3045F2C1B7D363D4F58C1858C30ABBBB0F41E4B2E18AF680553CA9C3689078E215C097086E47A4393BCA715C7A5D2C180D8750F35C6798944F79CC5000A";
    signature.publicKey = @"b0011765082a9352e04678ef38d38046dc01306edef676547456c0c23e270aaed7ffe9e31477";
    TransactionSubmitRequest *submitRequest = [TransactionSubmitRequest new];
    [submitRequest setTransactionBlob : transactionBlob];
    [submitRequest addSignature : signature];
    
    // 调用submit接口
    TransactionSubmitResponse *submitResponse = [transactionServer submit : submitRequest];
    if (submitResponse.errorCode == 0) {
        NSLog(@"submit response: %@", [submitResponse yy_modelToJSONString]);
    } else {
        NSLog(@"error: %@", submitResponse.errorDesc);
    }
    

getInfo

  • 接口说明

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

  • 调用方法

    TransactionGetInfoResponse *) getInfo : (TransactionGetInfoRequest *) transactionGetInfoRequest;

  • 请求参数

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

    参数类型描述
    totalCountint64_t返回的总交易数
    transactionsNSArray<TransactionHistory *> *交易内容
  • 错误码

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

    // 初始化请求参数
    TransactionGetInfoRequest *request = [TransactionGetInfoRequest new];
    [request setHash: @"389d53e55929c997d22f25d3757b088e2e869403ac0f2d13712ba877762b3d45"];
    
    // 调用getInfo接口
    TransactionService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getTransactionService];
    TransactionGetInfoResponse *response = [service getInfo: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

操作结构

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

BaseOperation

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

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

AccountActivateOperation

  • 功能

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

  • 费用

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

  • 成员

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

AccountSetMetadataOperation

  • 功能

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

  • 费用

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

  • 成员

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

AccountSetPrivilegeOperation

  • 功能

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

  • 费用

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

  • 成员

    成员变量类型描述
    sourceAddressNSString*选填,操作源账户地址
    masterWeightNSString*选填,账户自身权重,大小限制[0, max(UINT32)]
    signersSignerInfo[]选填,签名者权重列表
    txThresholdNSString*选填,交易门限,大小限制[0, max(int64)]
    typeThresholdTypeThreshold[]选填,指定类型交易门限
    metadataNSString*选填,备注

AssetIssueOperation

  • 功能

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

  • 费用

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

  • 成员

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

AssetSendOperation

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

  • 功能

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

  • 费用

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

  • 成员

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

GasSendOperation

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

  • 功能

    该操作用于转移Gas。GasSendOperation继承于BaseOperation。

  • 费用

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

  • 成员

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

ContractCreateOperation

  • 功能

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

  • 费用

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

  • 成员

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

ContractInvokeByAssetOperation

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

  • 功能

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

  • 费用

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

  • 成员

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

ContractInvokeByGasOperation

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

  • 功能

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

  • 费用

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

  • 成员

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

LogCreateOperation

  • 功能

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

  • 费用

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

  • 成员

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

账户服务

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

checkValid

  • 接口说明

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

  • 调用方法

    (AccountCheckValidResponse *) checkValid : (AccountCheckValidRequest *) accountCheckValidRequest;

  • 请求参数

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

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

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

    // 初始化请求参数
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountCheckValidRequest *request = [AccountCheckValidRequest new];
    [request setAddress:@"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C"];
    
    // 调用checkValid接口
    AccountCheckValidResponse *response = [accountService checkValid: nil];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

create

  • 接口说明

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

  • 调用方法

    (AccountCreateResponse *) create;

  • 响应数据

    参数类型描述
    privateKeyNSString *私钥
    publicKeyNSString *公钥
    addressNSString *地址
  • 错误码

    异常错误码描述
    SYSTEM_ERROR20000System error
  • 示例

    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountCreateResponse *response = [accountService create];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

getInfo-Account

  • 接口说明

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

  • 调用方法

    (AccountGetInfoResponse *) getInfo : (AccountGetInfoRequest *) accountGetInfoRequest;

  • 请求参数

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

    参数类型描述
    addressNSString*账户地址
    balanceint64_t账户余额,单位UGas,1 Gas = 10^8 UGas, 必须大于0
    nonceint64_t账户交易序列号,必须大于0
    privPriv*账户权限
  • 错误码

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

    // 初始化请求参数
    NSString *address = @"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C";
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountGetInfoRequest *request = [AccountGetInfoRequest new];
    [request setAddress : address];
    
    // 调用getInfo接口
    AccountGetInfoResponse *response = [accountService getInfo : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

getNonce

  • 接口说明

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

  • 调用方法

    (AccountGetNonceResponse *) getNonce : (AccountGetNonceRequest *) accountGetNonceRequest;

  • 请求参数

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

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

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

    // 初始化请求参数
    NSString *address = @"adxSk9MTT6aGoMxjAxuEGt1agRvWWnng25RF2";
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountGetNonceRequest * request = [AccountGetNonceRequest new];
    [request setAddress : address];
    
    // 调用getNonce接口
    AccountGetNonceResponse *response = [accountService getNonce : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

getBalance

  • 接口说明

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

  • 调用方法

    (AccountGetBalanceResponse *) getBalance : (AccountGetBalanceRequest *) accountGetBalanceRequest;

  • 请求参数

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

    参数类型描述
    balanceint64_tGas的余额, 单位UGas,1 Gas = 10^8 UGas,
  • 错误码

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

    // 初始化请求参数
    NSString *address = @"adxSk9MTT6aGoMxjAxuEGt1agRvWWnng25RF2";
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountGetBalanceRequest * request = [AccountGetBalanceRequest new];
    [request setAddress : address];
    
    // 调用getBalance接口
    AccountGetBalanceResponse *response = [accountService getBalance : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

getAssets

  • 接口说明

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

  • 调用方法

    (AccountGetAssetsResponse *) getAssets : (AccountGetAssetsRequest *) accountGetAssetsRequest;

  • 请求参数

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

    参数类型描述
    assetNSArray<AssetInfo *> *账户资产
  • 错误码

    异常错误码描述
    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
  • 示例

    // 初始化请求参数
    NSString *address = @"adxSmZHjDopQam2y5ntvHhGk4XEkiXc9MnFWZ";
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountGetAssetsRequest * request = [AccountGetAssetsRequest new];
    [request setAddress : address];
    
    // 调用getAssets接口
    AccountGetAssetsResponse *response = [accountService getAssets : request];
    if (response.errorCode == 0) {
        //AssetInfo *assetInfo = [response.result.assets objectAtIndex : 0];
        //NSLog(@"%@, %@", assetInfo.key.code, assetInfo.key.issuer);
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

getMetadata

  • 接口说明

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

  • 调用方法

    AccountGetMetadataResponse *) getMetadata : (AccountGetMetadataRequest *) accountGetMetadataRequest;

  • 请求参数

    参数类型描述
    addressNSString*必填,待查询的账户地址
    keyNSString*选填,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
  • 示例

    // 初始化请求参数
    NSString *address = @"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C";
    AccountService *accountService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAccountService];
    AccountGetMetadataRequest * request = [AccountGetMetadataRequest new];
    [request setAddress : address];
    
    // 调用getMetadata接口
    AccountGetMetadataResponse *response = [accountService getMetadata : request];
    if (response.errorCode == 0) {
        //MetadataInfo *metadataInfo = [response.result.metadatas objectAtIndex:0];
        //NSLog(@"%@, %@. %lld", metadataInfo.key, metadataInfo.value, metadataInfo.version);
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

资产服务

账户服务主要是资产相关的接口,目前有1个接口:getInfo

getInfo-Asset

  • 接口说明

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

  • 调用方法

    AssetGetInfoResponse *) getInfo : (AssetGetInfoRequest *) assetGetRequest;

  • 请求参数

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

    参数类型描述
    assetNSArray<AssetInfo *> *账户资产
  • 错误码

    异常错误码描述
    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
    SYSTEM_ERROR20000System error
  • 示例

    // 初始化请求参数
    NSString *address = @"adxSmZHjDopQam2y5ntvHhGk4XEkiXc9MnFWZ";
    NSString *code = @"TST";
    NSString *issuer = @"adxSdV6qWfyhJAmzrPbv3btsPPT6aFrqBku3C";
    AssetGetInfoRequest *request = [AssetGetInfoRequest new];
    [request setAddress : address];
    [request setCode : code];
    [request setIssuer : issuer];
    
    // 调用getInfo消息
    AssetService *assetService = [[[SDK sharedInstance] setUrl:@"http://seed1-node.bubi.cn"] getAssetService];
    AssetGetInfoResponse *response = [assetService getInfo : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    } else {
        NSLog(@"%@", response.errorDesc);
    }
    

合约服务

合约服务主要是合约相关的接口,目前有4个接口:checkValid、getInfo、getAddress、call

checkValid-Contract

  • 接口说明

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

  • 调用方法

    ContractCheckValidResponse *) checkValid : (ContractCheckValidRequest *) contractCheckValidRequest;

  • 请求参数

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

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

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

    // 初始化请求参数
    ContractCheckValidRequest *request = [ContractCheckValidRequest new];
    [request setContractAddress: @"adxSYQ8iMyZ7Dkj1oX1kjGMV55WXvoPKcLEK3"];
    
    // 调用checkValid接口
    ContractService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getContractService];
    ContractCheckValidResponse *response = [service checkValid: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getInfo-Contract

  • 接口说明

    该接口用于查询合约代码

  • 调用方法

    ContractGetInfoResponse *) getInfo : (ContractGetInfoRequest *) contractGetInfoRequest;

  • 请求参数

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

    参数类型描述
    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
  • 示例

    // 初始化请求参数
    ContractGetInfoRequest *request = [ContractGetInfoRequest new];
    [request setContractAddress: @"adxSYQ8iMyZ7Dkj1oX1kjGMV55WXvoPKcLEK3"];
    
    // 调用getInfo接口
    ContractService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getContractService];
    ContractGetInfoResponse *response = [service getInfo: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getAddress

  • 接口说明

    该接口用于查询合约地址

  • 调用方法

    ContractGetAddressResponse *) getAddress : (ContractGetAddressRequest *) contractGetAddressRequest;

  • 请求参数

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

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

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

    // 初始化请求参数
    ContractGetAddressRequest *request = [ContractGetAddressRequest new];
    [request setHash: @"44246c5ba1b8b835a5cbc29bdc9454cdb9a9d049870e41227f2dcfbcf7a07689"];
    
    // 调用getAddress接口
    ContractService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getContractService];
    ContractGetAddressResponse *response = [service getAddress: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

call

  • 接口说明

    该接口用于调试合约代码

  • 调用方法

    ContractCallResponse *) call : (ContractCallRequest *) contractCallRequest;

  • 请求参数

    参数类型描述
    sourceAddressNSString*选填,合约触发账户地址
    contractAddressNSString*选填,合约账户地址,与code不能同时为空
    codeNSString*选填,合约代码,与contractAddress不能同时为空,长度限制[1, 64]
    inputNSString*选填,合约入参
    contractBalanceint64_t选填,赋予合约的初始 Gas 余额, 单位UGas,1 Gas = 10^8 UGas, 大小限制[1, max(int64)]
    optTypeint32_t必填,0: 调用合约的读写接口 init, 1: 调用合约的读写接口 main, 2 :调用只读接口 query
    feeLimitint64_t交易要求的最低手续费, 大小限制[1, max(int64)]
    gasPriceint64_t交易费用单价,按字节收费,大小限制[1000, max(int64)]
  • 响应数据

    参数类型描述
    logsJSONObject日志信息
    queryRetsJSONArray查询结果集
    statContractStat*合约资源占用信息
    txsNSArray<TransactionEnvs *> *交易集
  • 错误码

    异常错误码描述
    INVALID_SOURCGasDDRESS_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
  • 示例

    // 初始化请求参数
    ContractCallRequest *request = [ContractCallRequest new];
    [request setCode : @"\"use strict\";log(undefined);function query() { getBalance(thisAddress); }"];
    [request setFeeLimit : 1000000000];
    [request setOptType : 2];
    
    // 调用call接口
    ContractService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getContractService];
    ContractCallResponse *response = [service call : request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

区块服务

区块服务主要是区块相关的接口,目前有11个接口:getNumber、checkStatus、getTransactions、getInfo、getLatestInfo、getValidators、getLatestValidators、getReward、getLatestReward、getFees、getLatestFees。

getNumber

  • 接口说明

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

  • 调用方法

    BlockGetNumberResponse *) getNumber;

  • 响应数据

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

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

    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetNumberResponse *response = [service getNumber];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

checkStatus

  • 接口说明

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

  • 调用方法

    BlockCheckStatusResponse *) checkStatus;

  • 响应数据

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

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

    // 调用checkStatus
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockCheckStatusResponse *response = [service checkStatus];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getTransactions

  • 接口说明

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

  • 调用方法

    BlockGetTransactionsResponse getTransactions(BlockGetTransactionsRequest);

  • 请求参数

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

    参数类型描述
    totalCountint64_t返回的总交易数
    transactionsNSArray<TransactionHistory *> *交易内容
  • 错误码

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

    // 初始化请求参数
    BlockGetTransactionsRequest *request = [BlockGetTransactionsRequest new];
    [request setBlockNumber: 617247];
    
    // 调用getTransactions接口
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetTransactionsResponse *response = [service getTransactions: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getInfo-Block

  • 接口说明

    该接口用于获取区块信息

  • 调用方法

    BlockGetInfoResponse *) getInfo : (BlockGetInfoRequest *) blockGetInfoRequest;

  • 请求参数

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

    参数类型描述
    closeTimeint64_t区块关闭时间
    numberint64_t区块高度
    txCountint64_t交易总量
    versionNSString*区块版本
  • 错误码

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

    // 初始化请求参数
    BlockGetInfoRequest *request = [BlockGetInfoRequest new];
    [request setBlockNumber: 617247];
    
    // 调用getInfo接口
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetInfoResponse *response = [service getInfo: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getLatestInfo

  • 接口说明

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

  • 调用方法

    BlockGetLatestInfoResponse *) getLatestInfo;

  • 响应数据

    参数类型描述
    closeTimeint64_t区块关闭时间
    numberint64_t区块高度,对应底层字段seq
    txCountint64_t交易总量
    versionNSString*区块版本
  • 错误码

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

    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetLatestInfoResponse *response = [service getLatestInfo];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getValidators

  • 接口说明

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

  • 调用方法

    BlockGetValidatorsResponse *) getValidators : (BlockGetValidatorsRequest *) blockGetValidatorsRequest;

  • 请求参数

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

    参数类型描述
    validatorsNSArray<ValidatorInfo *> *验证节点列表
  • 错误码

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

    // 初始化请求参数
    BlockGetValidatorsRequest *request = [BlockGetValidatorsRequest new];
    [request setBlockNumber: 617247];
    
    // 调用getValidators接口
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetValidatorsResponse *response = [service getValidators: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getLatestValidators

  • 接口说明

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

  • 调用方法

    BlockGetLatestValidatorsResponse *) getLatestValidators;

  • 响应数据

    参数类型描述
    validatorsNSArray<ValidatorInfo *> *验证节点列表
  • 错误码

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

    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetLatestValidatorsResponse *response = [service getLatestValidators];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getReward

  • 接口说明

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

  • 调用方法

    BlockGetRewardResponse *) getReward : (BlockGetRewardRequest *) blockGetRewardRequest;

  • 请求参数

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

    参数类型描述
    blockRewardint64_t区块奖励数
    validatorsRewardNSArray<ValidatorReward *> *验证节点奖励情况
  • 错误码

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

    // 初始化请求参数
    BlockGetRewardRequest *request = [BlockGetRewardRequest new];
    [request setBlockNumber: 617247];
    
    // 调用getReward接口
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetRewardResponse *response = [service getReward: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getLatestReward

  • 接口说明

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

  • 调用方法

    BlockGetLatestRewardResponse *) getLatestReward;

  • 响应数据

    参数类型描述
    blockRewardint64_t区块奖励数
    validatorsRewardNSArray<ValidatorReward *> *验证节点奖励情况
  • 错误码

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

    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetLatestRewardResponse *response = [service getLatestReward];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getFees

  • 接口说明

    获取指定区块中的账户最低资产限制和费用单价,按字节收费

  • 调用方法

    BlockGetFeesResponse *) getFees : (BlockGetFeesRequest *) blockGetFeesRequest;

  • 请求参数

    参数类型描述
    blockNumberint64_t必填,待查询的区块高度,必须大于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
  • 示例

    // 初始化请求参数
    BlockGetFeesRequest *request = [BlockGetFeesRequest new];
    [request setBlockNumber: 617247];
    
    // 调用getFees接口
    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetFeesResponse *response = [service getFees: request];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

getLatestFees

  • 接口说明

    该接口用于获取最新区块中的账户最低资产限制和费用单价,按字节收费

  • 调用方法

    BlockGetLatestFeesResponse *) getLatestFees;

  • 响应数据

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

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

    BlockService *service = [[[SDK sharedInstance] setUrl: @"http://seed1-node.bubi.cn"] getBlockService];
    BlockGetLatestFeesResponse *response = [service getLatestFees];
    if (response.errorCode == 0) {
        NSLog(@"%@", [response.result yy_modelToJSONString]);
    }
    else {
        NSLog(@"error: %@", response.errorDesc);
    }
    

数据对象

Priv
成员类型描述
masterWeightint64_t账户自身权重,大小限制[0, max(uint32)]
signersNSArray<SignerInfo *> *签名者权重列表
thresholdThreshold*门限
SignerInfo
成员类型描述
addressNSString*签名者区块链账户地址
weightint64_t签名者权重,大小限制[0, max(uint32)]
Threshold
成员类型描述
txThresholdint64_t交易默认门限,大小限制[0, max(int64)]
typeThresholdsNSArray<TypeThreshold *> *不同类型交易的门限
TypeThreshold
成员类型描述
typeint64_t操作类型,必须大于0
thresholdint64_t门限值,大小限制[0, max(int64)]
AssetInfo
成员类型描述
keyAssetKeyInfo*资产惟一标识
assetAmountint64_t资产数量
AssetKeyInfo
成员类型描述
codeNSString*资产编码
issuerNSString*资产发行账户地址
MetadataInfo
成员类型描述
keyNSString*metadata的关键词
valueNSString*metadata的内容
versionint64_tmetadata的版本
ContractInfo
成员类型描述
typeint32_t合约类型,默认0
payloadNSString*合约代码
ContractAddressInfo
成员类型描述
contractAddressNSString*合约地址
operationIndexint32_t所在操作的下标
ContractStat
成员类型描述
applyTimeint64_t接收时间
memoryUsageint64_t内存占用量
stackUsageint64_t堆栈占用量
stepint64_t几步完成
TransactionEnvs
成员类型描述
transactionEnvTransactionEnv*交易
TransactionEnv
成员类型描述
transactionTransactionInfo*交易内容
triggerContractTrigger*合约触发者
TransactionInfo
成员类型描述
sourceAddressNSString*交易发起的源账户地址
feeLimitint64_t交易要求的最低费用
gasPriceint64_t交易费用单价,按字节收费,单位UGas,1 Gas = 10^8 UGas
nonceint64_t交易序列号
operationsNSArray<OperationInfo *> *操作列表
ContractTrigger
成员类型描述
transactionTriggerTransaction*触发交易
OperationInfo
成员类型描述
typeint32_t操作类型
sourceAddressNSString*操作发起源账户地址
metadataNSString*备注
createAccountOperationCreateAccount*创建账户操作
issueAssetOperationIssueAsset*发行资产操作
payAssetOperationPayAsset*转移资产操作
payCoinOperationPayCoin*发送Gas操作
setMetadataOperationSetMetadata*设置metadata操作
setPrivilegeOperationSetPrivilege*设置账户权限操作
logOperationLog*记录日志
TriggerTransaction
成员类型描述
hashNSString*交易hash
OperationCreateAccount
成员类型描述
destAddressNSString*目标账户地址
contractContract*合约信息
privPriv*账户权限
metadataNSArray<MetadataInfo *> *账户
initBalanceint64_t账户资产, 单位UGas,1 Gas = 10^8 UGas,
initInputNSString*合约init函数的入参
Contract
成员类型描述
typeint32_t约的语种,默认不赋值
payloadNSString*对应语种的合约代码
MetadataInfo
成员类型描述
keyNSString*metadata的关键词
valueNSString*metadata的内容
versionint64_tmetadata的版本
OperationIssueAsset
成员类型描述
codeNSString*资产编码
assetAmountint64_t资产数量
OperationPayAsset
成员类型描述
destAddressNSString*待转移的目标账户地址
assetAssetInfo*账户资产
inputNSString*合约main函数入参
OperationPayCoin
成员类型描述
destAddressNSString*待转移的目标账户地址
gasAmountint64_t待转移的Gas数量
inputNSString*合约main函数入参
OperationSetMetadata
成员类型描述
keyNSString*metadata的关键词
valueNSString*metadata的内容
versionint64_tmetadata的版本
deleteFlagboolean是否删除metadata
OperationSetPrivilege
成员类型描述
masterWeightNSString*账户自身权重,大小限制[0, max(uint32)]
signersNSArray<SignerInfo *> *签名者权重列表
txThresholdNSString*交易门限,大小限制[0, max(int64)]
typeThresholdTypeThreshold*指定类型交易门限
OperationLog
成员类型描述
topicNSString*日志主题
dataNSArray<NSString *> *日志内容
TestTx
成员类型描述
transactionEnvTestTransactionFees*评估交易费用
TestTransactionFees
成员类型描述
transactionFeesTransactionFees*交易费用
TransactionFees
成员类型描述
feeLimitint64_t交易要求的最低费用
gasPriceint64_t交易费用单价,按字节收费,单位UGas,1 Gas = 10^8 UGas
SignatureInfo
成员类型描述
signDataint64_t签名后数据
publicKeyint64_t公钥
TransactionHistory
成员类型描述
actualFeeNSString*交易实际费用
closeTimeint64_t交易关闭时间
errorCodeint64_t交易错误码
errorDescNSString*交易描述
hashNSString*交易hash
ledgerSeqint64_t区块序列号
transactionTransactionInfo*交易内容列表
signaturesNSArray<SignatureInfo *> *签名列表
txSizeint64_t交易大小
ValidatorInfo
成员类型描述
addressNSString*共识节点地址
plegeCoinAmountint64_t验证节点押金
ValidatorReward
成员类型描述
validatorNSString*验证节点地址
rewardint64_t验证节点奖励
Fees
成员类型描述
baseReserveint64_t账户最低资产限制
gasPriceint64_t交易费用单价,按字节收费,单位UGas,1 Gas = 10^8 UGas

错误码

异常错误码描述
ACCOUNT_CREATE_ERROR11001Failed to create the account
INVALID_SOURCGasDDRESS_ERROR11002Invalid sourceAddress
INVALID_DESTADDRESS_ERROR11003Invalid destAddress
INVALID_INITBALANCE_ERROR11004InitBalance must be between 1 and max(int64)
SOURCGasDDRESS_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 greater 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 asset code must be between 1 and 64
INVALID_ASSET_AMOUNT_ERROR11024AssetAmount must be between 0 and max(int64)
INVALID_GAS_AMOUNT_ERROR11026GasAmount 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)
SOURCGasDDRESS_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 and 1024
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 greater than 0
OPERATIONS_ONE_ERROR11053One of the operations cannot be resolved
INVALID_SIGNATURENUMBER_ERROR11054SignagureNumber must be between 1 and max(int32)
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
← PHP隐私交易 JNI →
  • 概述
  • 环境要求
  • 安装
  • 请求与响应数据格式
    • 请求参数
    • 响应数据
  • 快速使用
    • 生成SDK实例
    • 生成公私钥地址
    • 有效性校验
    • 查询
    • 广播交易
  • 具体方法
    • 交易服务
    • 操作结构
    • 账户服务
    • 资产服务
    • 合约服务
    • 区块服务
    • 数据对象
  • 错误码
Copyright © 2020