Skip to content

Commit

Permalink
feat: add get_header and get_header_by_number rpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
BaojunCZ committed Jul 29, 2019
1 parent 4cffc5c commit 696fb4d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/ckb_rpc/ckb_api_client.dart
Expand Up @@ -74,6 +74,16 @@ class CKBApiClient {
return result == null ? null : CellbaseOutputCapacity.fromJson(result);
}

Future<Header> getHeader(String blockHash) async {
final result = await _request.requestRpc(ServiceUrl.getHeader, [blockHash]);
return result == null ? null : Header.fromJson(result);
}

Future<Header> getHeaderByNumber(String blockNumber) async {
final result = await _request.requestRpc(ServiceUrl.getHeaderByNumber, [blockNumber]);
return result == null ? null : Header.fromJson(result);
}

//==========================Experiment RPC Methods==================================

Future<String> computeTransactionHash(Transaction transaction) async {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/ckb_rpc/service_url.dart
Expand Up @@ -13,6 +13,8 @@ class ServiceUrl {
static final tipHeader = "get_tip_header";
static final transaction = "get_transaction";
static final cellbaseOutputCapacity = "get_cellbase_output_capacity_details";
static final getHeader = "get_header";
static final getHeaderByNumber = "get_header_by_number";

//Experiment
static final computeTransactionHash = '_compute_transaction_hash';
Expand Down
1 change: 1 addition & 0 deletions lib/src/ckb_types/header.dart
@@ -1,6 +1,7 @@
part of 'package:ckb_sdk/ckb_types.dart';

class Header {
String dao;
String difficulty;
String hash;
String number;
Expand Down
21 changes: 21 additions & 0 deletions test/api/chain_rpc_test.dart
Expand Up @@ -152,6 +152,27 @@ main() {
}
});

test("get header", () async {
try {
Header header = await apiClient
.getHeader("0xac1766e14aa988b41d6ac3fe8216a1ab83f10359ca34478a8c0902069cbb0296");
expect(header != null, true);
} catch (error) {
print(error.toString());
expect(true, true);
}
});

test("get header by blockNumber", () async {
try {
Header header = await apiClient.getHeaderByNumber("1");
expect(header != null, true);
} catch (error) {
print(error.toString());
expect(true, true);
}
});

group("get transaction", () {
test("with right params", () async {
try {
Expand Down

0 comments on commit 696fb4d

Please sign in to comment.