Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
feat: Add new chain RPC method get_cellbase_output_capacity_details
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Jul 29, 2019
1 parent e1c45f8 commit 85b2f8a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CKB.xcodeproj/project.pbxproj
Expand Up @@ -71,6 +71,8 @@
1A4AEBDB2282EB0100F0D576 /* TxPoolInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A4AEBDA2282EB0100F0D576 /* TxPoolInfo.swift */; };
1A54E26122EEA9DE008CF6C3 /* setBan.json in Resources */ = {isa = PBXBuildFile; fileRef = 1A55D39C22EEA7CC00E2B8DE /* setBan.json */; };
1A54E26222EEA9E1008CF6C3 /* getBannedAddresses.json in Resources */ = {isa = PBXBuildFile; fileRef = 1A55D39E22EEA7F300E2B8DE /* getBannedAddresses.json */; };
1A54E26622EEB4D4008CF6C3 /* BlockReward.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A54E26522EEB4D4008CF6C3 /* BlockReward.swift */; };
1A54E26822EEB5BA008CF6C3 /* blockReward.json in Resources */ = {isa = PBXBuildFile; fileRef = 1A54E26722EEB5BA008CF6C3 /* blockReward.json */; };
1A55D39B22EEA69F00E2B8DE /* BannedAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A55D39A22EEA69F00E2B8DE /* BannedAddress.swift */; };
1A5BCBB3228C571200157426 /* Transaction+Sign.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A5BCBB2228C571200157426 /* Transaction+Sign.swift */; };
1AA9B6842283CD4C00C116B2 /* ChainInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AA9B6832283CD4C00C116B2 /* ChainInfo.swift */; };
Expand Down Expand Up @@ -149,6 +151,8 @@
1A4AEBDA2282EB0100F0D576 /* TxPoolInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxPoolInfo.swift; sourceTree = "<group>"; };
1A4AEBDC2282EC9700F0D576 /* txPoolInfo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = txPoolInfo.json; sourceTree = "<group>"; };
1A4AEBDE2282EF7500F0D576 /* peers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = peers.json; sourceTree = "<group>"; };
1A54E26522EEB4D4008CF6C3 /* BlockReward.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BlockReward.swift; path = "../../../../../../System/Volumes/Data/Users/james/Projects/ckb-sdk-swift/Source/Types/BlockReward.swift"; sourceTree = "<group>"; };
1A54E26722EEB5BA008CF6C3 /* blockReward.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = blockReward.json; path = "../../../../../../../System/Volumes/Data/Users/james/Projects/ckb-sdk-swift/Tests/API/RPC Fixtures/blockReward.json"; sourceTree = "<group>"; };
1A55D39A22EEA69F00E2B8DE /* BannedAddress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BannedAddress.swift; path = "../../../../../../System/Volumes/Data/Users/james/Projects/ckb-sdk-swift/Source/Types/BannedAddress.swift"; sourceTree = "<group>"; };
1A55D39C22EEA7CC00E2B8DE /* setBan.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = setBan.json; path = "../../../../../../../System/Volumes/Data/Users/james/Projects/ckb-sdk-swift/Tests/API/RPC Fixtures/setBan.json"; sourceTree = "<group>"; };
1A55D39E22EEA7F300E2B8DE /* getBannedAddresses.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = getBannedAddresses.json; path = "../../../../../../../System/Volumes/Data/Users/james/Projects/ckb-sdk-swift/Tests/API/RPC Fixtures/getBannedAddresses.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -253,6 +257,7 @@
1A2CDAE22281796D0024CA71 /* epoch.json */,
1A58F43C2276981700C6546F /* transaction.json */,
1A58F43E2276994000C6546F /* header.json */,
1A54E26722EEB5BA008CF6C3 /* blockReward.json */,
1A58F4402276998900C6546F /* tipBlockNumber.json */,
1A58F442227699D400C6546F /* sendTransactionEmpty.json */,
1A58F44422769A0600C6546F /* localNodeInfo.json */,
Expand Down Expand Up @@ -361,6 +366,7 @@
1A2188732288FC1700F613CF /* DryRunResult.swift */,
1A199DEA22BA3225000C0C34 /* LockHashIndexState.swift */,
1A55D39A22EEA69F00E2B8DE /* BannedAddress.swift */,
1A54E26522EEB4D4008CF6C3 /* BlockReward.swift */,
);
path = Types;
sourceTree = "<group>";
Expand Down Expand Up @@ -570,6 +576,7 @@
1A2D6B3622A35C5A00724E66 /* computeTransactionHash.json in Resources */,
1A2D6B3B22A35C6400724E66 /* pubkey.json in Resources */,
1A2D6B3422A35C5A00724E66 /* peersState.json in Resources */,
1A54E26822EEB5BA008CF6C3 /* blockReward.json in Resources */,
1A2D6B3322A35C5A00724E66 /* blockchainInfo.json in Resources */,
1A2D6B2822A35C5A00724E66 /* genesisBlockHash.json in Resources */,
1A54E26222EEA9E1008CF6C3 /* getBannedAddresses.json in Resources */,
Expand Down Expand Up @@ -716,6 +723,7 @@
1A199DEB22BA3225000C0C34 /* LockHashIndexState.swift in Sources */,
1A414A9621C37AA000B28C09 /* Script.swift in Sources */,
1AB7516822B9F2DB00AC9F63 /* APIClient+Pool.swift in Sources */,
1A54E26622EEB4D4008CF6C3 /* BlockReward.swift in Sources */,
1A55D39B22EEA69F00E2B8DE /* BannedAddress.swift in Sources */,
1AD3195D225DBA0B00F41790 /* AddressGenerator.swift in Sources */,
1A414AA021C770DD00B28C09 /* Utils.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Source/API/APIClient+Chain.swift
Expand Up @@ -54,4 +54,8 @@ public extension APIClient {
func getEpochByNumber(number: EpochNumber) throws -> Epoch {
return try load(APIRequest<Epoch>(method: "get_epoch_by_number", params: [number]))
}

func getCellbaseOutputCapacityDetails(blockHash: H256) throws -> BlockReward {
return try load(APIRequest<BlockReward>(method: "get_cellbase_output_capacity_details", params: [blockHash]))
}
}
23 changes: 23 additions & 0 deletions Source/Types/BlockReward.swift
@@ -0,0 +1,23 @@
//
// BlockReward.swift
//
// Copyright © 2019 Nervos Foundation. All rights reserved.
//

import Foundation

public struct BlockReward: Codable {
public let proposalReward: Capacity
public let primary: Capacity
public let secondary: Capacity
public let total: Capacity
public let txFee: Capacity

enum CodingKeys: String, CodingKey {
case proposalReward = "proposal_reward"
case primary
case secondary
case total
case txFee = "tx_fee"
}
}
7 changes: 7 additions & 0 deletions Tests/API/APIClientTests.swift
Expand Up @@ -55,6 +55,13 @@ class APIClientTests: RPCTestSkippable {
XCTAssertNil(try? client.getTransaction(hash: nonexistentHash))
}

func testGetCellbaseOutputCapacityDetails() throws {
let tipHeader = try client.getTipHeader()
let result = try client.getCellbaseOutputCapacityDetails(blockHash: tipHeader.hash)
XCTAssertNotNil(result)
XCTAssert(Int64(result.txFee)! >= 0)
}

func testGetBlockHash() throws {
let result = try client.getBlockHash(number: "0")
XCTAssertNotNil(result)
Expand Down
6 changes: 6 additions & 0 deletions Tests/API/APIMockingTests.swift
Expand Up @@ -41,6 +41,12 @@ class APIMockingTests: XCTestCase {
XCTAssertNotNil(result)
}

func testGetCellbaseOutputCapacityDetails() throws {
let result = try getClient(json: "blockReward").getCellbaseOutputCapacityDetails(blockHash: "0xba0d878d2c3711d38b5ddc2bc917312ca3898cad98457cc7960e28ec31f26e7f")
XCTAssertNotNil(result)
XCTAssert(Int64(result.txFee)! >= 0)
}

func testGetBlockHash() throws {
let result = try? getClient(json: "genesisBlockHash").getBlockHash(number: "0")
XCTAssertNotNil(result)
Expand Down
11 changes: 11 additions & 0 deletions Tests/API/RPC Fixtures/blockReward.json
@@ -0,0 +1,11 @@
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"primary": "100000000000",
"proposal_reward": "0",
"secondary": "3936000",
"total": "100003936000",
"tx_fee": "0"
}
}

0 comments on commit 85b2f8a

Please sign in to comment.