This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
/
APIClient+Chain.swift
64 lines (50 loc) · 2.38 KB
/
APIClient+Chain.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// APIClient+Chain.swift
//
// Copyright © 2019 Nervos Foundation. All rights reserved.
//
import Foundation
public extension APIClient {
func getBlock(hash: H256) throws -> Block {
return try load(APIRequest<Block>(method: "get_block", params: [hash]))
}
func getBlockByNumber(number: BlockNumber) throws -> Block {
return try load(APIRequest<Block>(method: "get_block_by_number", params: [number.hexString]))
}
func getTransaction(hash: H256) throws -> TransactionWithStatus {
return try load(APIRequest<TransactionWithStatus>(method: "get_transaction", params: [hash]))
}
func getBlockHash(number: BlockNumber) throws -> H256 {
return try load(APIRequest<String>(method: "get_block_hash", params: [number.hexString]))
}
func getTipHeader() throws -> Header {
return try load(APIRequest<Header>(method: "get_tip_header"))
}
func getHeader(blockHash: H256) throws -> Header {
return try load(APIRequest<Header>(method: "get_header", params: [blockHash]))
}
func getHeaderByNumber(number: BlockNumber) throws -> Header {
return try load(APIRequest<Header>(method: "get_header_by_number", params: [number.hexString]))
}
func getCellsByLockHash(lockHash: H256, from: BlockNumber, to: BlockNumber) throws -> [CellOutputWithOutPoint] {
return try load(APIRequest<[CellOutputWithOutPoint]>(
method: "get_cells_by_lock_hash",
params: [lockHash, from.hexString, to.hexString]
))
}
func getLiveCell(outPoint: OutPoint, withData: Bool = true) throws -> CellWithStatus {
return try load(APIRequest<CellWithStatus>(method: "get_live_cell", params: [outPoint.param, withData]))
}
func getTipBlockNumber() throws -> BlockNumber {
return BlockNumber(hexValue: try load(APIRequest<HexString>(method: "get_tip_block_number")))!
}
func getCurrentEpoch() throws -> Epoch {
return try load(APIRequest<Epoch>(method: "get_current_epoch"))
}
func getEpochByNumber(number: EpochNumber) throws -> Epoch {
return try load(APIRequest<Epoch>(method: "get_epoch_by_number", params: [number.hexString]))
}
func getCellbaseOutputCapacityDetails(blockHash: H256) throws -> BlockReward? {
return try loadNullable(APIRequest<BlockReward>(method: "get_cellbase_output_capacity_details", params: [blockHash]))
}
}