Skip to content

Commit

Permalink
Merge pull request #75 from BaojunCZ/rc/v0.23.0
Browse files Browse the repository at this point in the history
Rc/v0.23.0
  • Loading branch information
BaojunCZ authored Oct 19, 2019
2 parents 3d5c3aa + 5d97ad9 commit 7ab4616
Show file tree
Hide file tree
Showing 55 changed files with 1,187 additions and 243 deletions.
20 changes: 12 additions & 8 deletions example/api_client_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ main() async {
print(jsonEncode(blockRes));
String blockHash = await apiClient.getBlockHash("20");
print(blockHash);
TransactionWithStatus transactionWithStatus = await apiClient
.getTransaction('0x3abd21e6e51674bb961bb4c5f3cee9faa5da30e64be10628dc1cef292cbae324');
TransactionWithStatus transactionWithStatus = await apiClient.getTransaction(
'0x3abd21e6e51674bb961bb4c5f3cee9faa5da30e64be10628dc1cef292cbae324');
print(jsonEncode(transactionWithStatus));
Header header = await apiClient.getTipHeader();
print(header.number);

List<CellWithOutPoint> cells = await apiClient.getCellsByLockHash(
'0x0da2fe99fe549e082d4ed483c2e968a89ea8d11aabf5d79e5cbf06522de6e674', "1", "1000");
'0x0da2fe99fe549e082d4ed483c2e968a89ea8d11aabf5d79e5cbf06522de6e674',
"1",
"1000");
CellWithOutPoint cell = cells[0];
OutPoint point = cell.outPoint;
print(point.cell.txHash);
print(point.cell.index);
String blcokHash = cell.blcokHash;
print(blcokHash);

CellWithStatus liveCellRes = await apiClient.getLiveCell(OutPoint(
'', CellOutPoint("0x8d37f0856ebb70c12871830667d82224e6619896c7f12bb73a14dd9329af9c8d", "0")));
CellWithStatus liveCellRes = await apiClient.getLiveCell(
OutPoint(
"0x8d37f0856ebb70c12871830667d82224e6619896c7f12bb73a14dd9329af9c8d",
"0"),
true);
print(liveCellRes.cell.capacity);

String tipBlockNumber = await apiClient.getTipBlockNumber();
Expand Down
7 changes: 6 additions & 1 deletion lib/ckb_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class RPCErrorException extends RPCBaseException {

RPCErrorException(this.error, this.url) : super(url);

String toString() => '"$url": RPC Error Code ${error.code}, Message: ${error.message}';
String toString() =>
'"$url": RPC Error Code ${error.code}, Message: ${error.message}';
}

class InvalidNumberOfWitnessesException implements Exception {
Expand All @@ -50,6 +51,10 @@ class InvalidHashTypeException implements Exception {
String toString() => "Invalid hash type!";
}

class NoSystemContactException implements Exception {
String toString() => "Genesis block second transaction not found";
}

class CommonException {
final String message;

Expand Down
2 changes: 2 additions & 0 deletions lib/ckb_rpc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';

import 'package:ckb_sdk/ckb_sdk.dart';
import 'package:ckb_sdk/ckb_serialization.dart';
import 'package:http/http.dart' as http;

import 'ckb_error.dart';
Expand Down
23 changes: 23 additions & 0 deletions lib/ckb_serialization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:typed_data';

import 'package:ckb_sdk/ckb_sdk.dart';

part 'src/ckb_serialization/base/type.dart';
part 'src/ckb_serialization/base/dyn_type.dart';
part 'src/ckb_serialization/base/fixed_type.dart';

part 'src/ckb_serialization/fixed/byte1.dart';
part 'src/ckb_serialization/fixed/byte32.dart';
part 'src/ckb_serialization/fixed/empty.dart';
part 'src/ckb_serialization/fixed/fixed.dart';
part 'src/ckb_serialization/fixed/uint32.dart';
part 'src/ckb_serialization/fixed/uint64.dart';
part 'src/ckb_serialization/fixed/struct.dart';

part 'src/ckb_serialization/dynamic/bytes.dart';
part 'src/ckb_serialization/dynamic/dynamic.dart';
part 'src/ckb_serialization/dynamic/table.dart';

part 'src/ckb_serialization/serializer.dart';
part 'src/ckb_serialization/convert.dart';
part 'src/ckb_serialization/calculator.dart';
4 changes: 2 additions & 2 deletions lib/ckb_system_contract.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'ckb_address.dart';
import 'ckb_crypto.dart';
import 'package:ckb_sdk/ckb_error.dart';

import 'ckb_rpc.dart';
import 'ckb_types.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/ckb_types.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:ckb_sdk/ckb_serialization.dart';
import 'package:convert/convert.dart';

import 'ckb_crypto.dart';
Expand All @@ -8,7 +9,6 @@ import 'ckb_error.dart';
part 'src/ckb_types/block.dart';
part 'src/ckb_types/blockchain_info.dart';
part 'src/ckb_types/cell_input.dart';
part 'src/ckb_types/cell_out_point.dart';
part 'src/ckb_types/cell_output.dart';
part 'src/ckb_types/cell_with_outpoint.dart';
part 'src/ckb_types/cell_with_status.dart';
Expand All @@ -24,10 +24,10 @@ part 'src/ckb_types/transaction.dart';
part 'src/ckb_types/transaction_with_status.dart';
part 'src/ckb_types/tx_pool_info.dart';
part 'src/ckb_types/uncle_block.dart';
part 'src/ckb_types/witness.dart';
part 'src/ckb_types/live_cell.dart';
part 'src/ckb_types/lock_hash_index_state.dart';
part 'src/ckb_types/transaction_by_lock_hash.dart';
part 'src/ckb_types/transaction_point.dart';
part 'src/ckb_types/cell_base_output_capacity.dart';
part 'src/ckb_types/banned_address.dart';
part 'src/ckb_types/cell_dep.dart';
7 changes: 0 additions & 7 deletions lib/src/ckb_address/ckb_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,4 @@ class CKBAddress {

String _prefix() => network == CKBNetwork.Mainnet ? MainNetPrefix : TestNetPrefix;

String _binIdx(String binIdx) {
String result = "";
binIdx.codeUnits.forEach((code) {
result += numberToHex(code);
});
return result;
}
}
28 changes: 21 additions & 7 deletions lib/src/ckb_crypto/number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ String remove0x(String hex) => hex.startsWith("0x") ? hex.substring(2) : hex;

String hexAdd0x(String hex) => hex.startsWith("0x") ? hex : "0x$hex";

String numberToHex(dynamic number, {bool pad = false, bool include0x = false, int forcePadLen}) {
String numberToHex(dynamic number,
{bool pad = false, bool include0x = false, int forcePadLen}) {
String toHexSimple() {
if (number is int) {
return number.toRadixString(16);
Expand All @@ -25,11 +26,22 @@ String numberToHex(dynamic number, {bool pad = false, bool include0x = false, in
return hexString;
}

List<int> numberToBytes(dynamic number) =>
number is BigInt ? pc_utils.encodeBigInt(number) : hex.decode(numberToHex(number, pad: true));
List<int> numberToBytes(dynamic number) => number is BigInt
? pc_utils.encodeBigInt(number)
: hex.decode(numberToHex(number, pad: true));

String bytesToHex(List<int> bytes, {bool pad = false, bool include0x = false, int forcePadLen}) =>
numberToHex(bytesToInt(bytes), pad: pad, include0x: include0x, forcePadLen: forcePadLen);
String bytesToHex(List<int> bytes,
{bool pad = false, bool include0x = false, int forcePadLen}) =>
numberToHex(bytesToInt(bytes),
pad: pad, include0x: include0x, forcePadLen: forcePadLen);

String toHex(String input) {
if (input.startsWith("0x")) {
return input;
} else {
return numberToHex(BigInt.parse(input, radix: 16));
}
}

List<int> intToBytes(BigInt number) => pc_utils.encodeBigInt(number);

Expand Down Expand Up @@ -61,7 +73,8 @@ List<int> toBytesPadded(BigInt value, int length) {
}

if (bytesLength > length) {
throw CommonException("Input is too large to put in byte array of size " + length.toString());
throw CommonException(
"Input is too large to put in byte array of size " + length.toString());
}

int destOffset = length - bytesLength;
Expand Down Expand Up @@ -102,7 +115,8 @@ Uint8List hexStringToByteArray(String input) {
}

for (int i = startIdx; i < len; i += 2) {
data[(i + 1) ~/ 2] = (digitHex(cleanInput[i]) << 4) + digitHex(cleanInput[i + 1]);
data[(i + 1) ~/ 2] =
(digitHex(cleanInput[i]) << 4) + digitHex(cleanInput[i + 1]);
}
return data;
}
Expand Down
Loading

0 comments on commit 7ab4616

Please sign in to comment.