bdledger-apis/test.md
2018-10-09 13:49:36 +08:00

13 KiB
Raw Blame History

Basic types

Error

message Error {
    string code = 1; // One of a server-defined set of error codes.
    string message = 2; // A human-readable representation of the error.
    string target = 3; // The target of the error.
    repeated Error details = 4; // An array of details about specific errors that led to this reported error.
}

ClientVersionResponse

message ClientVersionResponse {
    Error error = 1;
    string version = 2; // 节点客户端版本
}

TransactionType

enum TransactionType {
  RECORD = 0; // 通用数据记录
  MESSAGE = 1; // 消息
  CONTRACT_CREATION = 2; // 合约创建
  CONTRACT_INVOCATION = 3; // 合约调用
}

Transaction

message Transaction {
  uint64 block_number = 1; // 事务所在的区块的区块号,当事务处于待确认状态时为`null`
  bytes block_hash = 2; // 事务所在的区块的哈希,当事务处于待确认状态时为`null`
  uint32 index = 3; // 事务在区块中的位置index当事务处于待确认状态时为`null`
  bytes hash = 4; // 事务的哈希
  TransactionType type = 5; // 事务类型
  bytes from = 6; // 发送账户地址
  uint64 nonce = 7; // 这条事务之前发送者所发送的事务数量
  bytes to = 8; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建
  bytes data = 9; // 数据或合约代码
  bytes v = 10; // ECDSA recovery id
  bytes r = 11; // ECDSA signature r
  bytes s = 12; // ECDSA signature s
}

Block

message Block {
  uint64 number = 1; // 区块号,当区块处于待确认状态时为`null`
  bytes hash = 2; // 区块的哈希,当区块处于待确认状态时为`null`
  bytes parent_hash = 3; // 父区块的哈希
  bytes witness = 4; // 见证者账户地址
  uint64 timestamp = 5; // 区块产生时的UNIX时间戳
  uint64 size = 6; // 区块大小的字节数
  bytes transactions_root = 7; // 区块的事务树根
  repeated Transaction transactions = 8; // 事务对象的数组,或为空
  repeated bytes transaction_hashes = 9; // 32字节的交易哈希的数组或为空
}

BlockResponse

message BlockResponse {
    Error error = 1;
    Block block = 2;
}

TransactionResponse

message TransactionResponse {
    Error error = 1;
    Transaction transaction = 2;
}

Transaction ledger API

ClientVersion

Request

google.protobuf.Empty

Response

bdchain.api.ClientVersionResponse

Test cases

1

Request

(empty)

Response

error: (empty Error object)
version: 'TxLedgerGo/v0.0.1alpha/darwin/go1.11'

CreateLedger

Request

message CreateLedgerRequest {
  string name = 1;
}

Response

message CreateLedgerResponse {
  Error error = 1;
}

Test cases

1

Request

name: 'test'

Response

error: (empty Error object)
2

Request

Client:

name: null

On the wire:

name: '' (defualt value)

Response

error:
  code: 'BadArgument'
  message: 'name must not be empty'
  target: 'name'
  details:

GetLedgers

Request

google.protobuf.Empty

Response

message GetLedgersResponse {
  Error error = 1;
  repeated string ledgers = 2;
}

Test cases

1

Request

(empty)

Response

error: (empty Error object)
ledgers:
  - 'first'
  - 'second'
  - 'third' 

SendTransaction

Request

message SendTransactionRequest {
  string ledger = 1;
  message Transaction {
    TransactionType type = 1;
    bytes from = 2;
    bytes to = 3;
    bytes data = 4;
  }
  Transaction transaction = 2;
}

Response

message SendTransactionResponse {
  Error error = 1;
  bytes hash = 2;
}

Test cases

1

Request

ledger: 'test'
transaction:
  type: TransactionType.MESSAGE
  from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes)
  data: 0xdeadbeef (in bytes)

Response

error: (empty Error object)
hash: 0xd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5ed (in bytes)
2

Request

ledger: 'test'
transaction:
  type: TransactionType.MESSAGE
  from: null (in bytes)
  to: 0x5obada55 (in bytes)
  data: null (in bytes)

Response

error:
  code: 'BadArgument'
  message: 'Multiple errors in transaction'
  target: 'transaction'
  details:
    - code: 'EmptyValue'
      message: 'from must not be empty'
      target: 'from'
      details:
    - code: 'MalformedAddress'
      message: 'to must be a valid 32-byte address'
      target: 'to'
      details:
hash: (empty bytes, default value)

Accounting chain API

ClientVersion

Request

google.protobuf.Empty

Response

bdchain.api.ClientVersionResponse

Test cases

1

Request

(empty)

Response

error: (empty Error object)
version: 'AcChainGo/v0.0.1alpha/darwin/go1.11' 

BlockNumber

Request

message BlockNumberRequest {
  string ledger = 1;
}

Response

message BlockNumberResponse {
  Error error = 1;
  uint64 block_number = 2;
}

Test cases

1

Request

ledger: 'test'

Response

error: (empty Error object)
block_number: 2018
2

Request

Client:

ledger: null

On the wire:

ledger: '' (defualt value)

Response

error:
  code: 'BadArgument'
  message: 'name must not be empty'
  target: 'name'
  details:
block_number: 0 (default value)

GetBlockByNumber

Request

message GetBlockByNumberRequest {
  string ledger = 1;
  uint64 number = 2;
  bool full_transaction = 3;
}

Response

bdchain.api.BlockResponse

Test cases

1

Request

ledger: 'test'
number: 2018
full_transaction: true

Response

error: (empty Error object)
block: 
  number: 2018
  hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes)
  witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes)
  timestamp: 2018050400000
  size: 20180504
  transactions_root: 0x5obada555obada555obada555obada555obada555obada555obada555obada55 (in bytes)
  transactions:
    - block_number: 2018
      block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
      index: 0
      hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
      type: TransactionType.RECORD
      from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
      nonce: 2018
      to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
      data: 0xdeadbeef (in bytes)
      v: 0x25 (in bytes)
      r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes)
      s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes)
    - block_number: 2018
      block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
      index: 1
      hash: 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes)
      type: TransactionType.MESSAGE
      from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
      nonce: 2019
      to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes)
      data: (empty bytes, default value)
      v: 0x25 (in bytes)
      r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes)
      s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes)
  transaction_hashes:
2

Request

Client:

ledger: 'test'
number: 2018
full_transaction: null

On the wire:

ledger: 'test'
number: 2018
full_transaction: false (defualt value)

Response

error: (empty Error object)
block: 
  number: 2018
  hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes)
  witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes)
  timestamp: 2018050400000
  size: 20180504
  transactions_root: 0x5obada555obada555obada555obada555obada555obada555obada555obada55 (in bytes)
  transactions:
  transaction_hashes:
    - 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
    - 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes)

GetBlockByHash

Request

message GetBlockByHashRequest {
  string ledger = 1;
  bytes hash = 2;
  bool full_transaction = 3;
}

Response

bdchain.api.BlockResponse

Test cases

1

Request

ledger: 'test'
hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
full_transaction: false

Response

error: (empty Error object)
block: 
  number: 2018
  hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes)
  witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes)
  timestamp: 2018050400000
  size: 20180504
  transactions_root: 0x5obada555obada555obada555obada555obada555obada555obada555obada55 (in bytes)
  transactions:
  transaction_hashes:
    - 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
    - 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes)

GetTransactionByHash

Request

message GetTransactionByHashRequest {
  string ledger = 1;
  bytes hash = 2;
}

Response

bdchain.api.TransactionResponse

Test cases

1

Request

ledger: 'test'
hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)

Response

error: (empty Error object)
transaction:
  block_number: 2018
  block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  index: 0
  hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
  type: TransactionType.RECORD
  from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  nonce: 2018
  to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  data: 0xdeadbeef (in bytes)
  v: 0x25 (in bytes)
  r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes)
  s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes)

GetTransactionByBlockNumberAndIndex

Request

message GetTransactionByBlockNumberAndIndexRequest {
  string ledger = 1;
  uint64 block_number = 2;
  uint32 index = 3;
}

Response

bdchain.api.TransactionResponse

Test cases

1

Request

ledger: 'test'
block_number: 2018
index: 0

Response

error: (empty Error object)
transaction:
  block_number: 2018
  block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  index: 0
  hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
  type: TransactionType.RECORD
  from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  nonce: 2018
  to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  data: 0xdeadbeef (in bytes)
  v: 0x25 (in bytes)
  r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes)
  s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes)

GetTransactionByBlockHashAndIndex

Request

message GetTransactionByBlockHashAndIndexRequest {
  string ledger = 1;
  bytes block_hash = 2;
  uint32 index = 3;
}

Response

bdchain.api.TransactionResponse

Test cases

1

Request

ledger: 'test'
block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
index: 0

Response

error: (empty Error object)
transaction:
  block_number: 2018
  block_hash: 0xdeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcodedeadcode (in bytes)
  index: 0
  hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes)
  type: TransactionType.RECORD
  from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  nonce: 2018
  to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)
  data: 0xdeadbeef (in bytes)
  v: 0x25 (in bytes)
  r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes)
  s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes)