diff --git a/CKB.xcodeproj/project.pbxproj b/CKB.xcodeproj/project.pbxproj index ad25d0e..f7d2f45 100644 --- a/CKB.xcodeproj/project.pbxproj +++ b/CKB.xcodeproj/project.pbxproj @@ -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 */; }; @@ -149,6 +151,8 @@ 1A4AEBDA2282EB0100F0D576 /* TxPoolInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxPoolInfo.swift; sourceTree = ""; }; 1A4AEBDC2282EC9700F0D576 /* txPoolInfo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = txPoolInfo.json; sourceTree = ""; }; 1A4AEBDE2282EF7500F0D576 /* peers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = peers.json; sourceTree = ""; }; + 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 = ""; }; + 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 = ""; }; 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 = ""; }; 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 = ""; }; 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 = ""; }; @@ -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 */, @@ -361,6 +366,7 @@ 1A2188732288FC1700F613CF /* DryRunResult.swift */, 1A199DEA22BA3225000C0C34 /* LockHashIndexState.swift */, 1A55D39A22EEA69F00E2B8DE /* BannedAddress.swift */, + 1A54E26522EEB4D4008CF6C3 /* BlockReward.swift */, ); path = Types; sourceTree = ""; @@ -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 */, @@ -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 */, diff --git a/Source/API/APIClient+Chain.swift b/Source/API/APIClient+Chain.swift index 9da41a9..57317ae 100644 --- a/Source/API/APIClient+Chain.swift +++ b/Source/API/APIClient+Chain.swift @@ -54,4 +54,8 @@ public extension APIClient { func getEpochByNumber(number: EpochNumber) throws -> Epoch { return try load(APIRequest(method: "get_epoch_by_number", params: [number])) } + + func getCellbaseOutputCapacityDetails(blockHash: H256) throws -> BlockReward { + return try load(APIRequest(method: "get_cellbase_output_capacity_details", params: [blockHash])) + } } diff --git a/Source/Types/BlockReward.swift b/Source/Types/BlockReward.swift new file mode 100644 index 0000000..58dfeb7 --- /dev/null +++ b/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" + } +} diff --git a/Tests/API/APIClientTests.swift b/Tests/API/APIClientTests.swift index f2a38ab..6e31eab 100644 --- a/Tests/API/APIClientTests.swift +++ b/Tests/API/APIClientTests.swift @@ -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) diff --git a/Tests/API/APIMockingTests.swift b/Tests/API/APIMockingTests.swift index e27f02c..619675b 100644 --- a/Tests/API/APIMockingTests.swift +++ b/Tests/API/APIMockingTests.swift @@ -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) diff --git a/Tests/API/RPC Fixtures/blockReward.json b/Tests/API/RPC Fixtures/blockReward.json new file mode 100644 index 0000000..923e73e --- /dev/null +++ b/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" + } +}