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

Commit

Permalink
feat: change get_cells_by_type_hash to get_cells_by_lock_hash
Browse files Browse the repository at this point in the history
updating input/output structures
  • Loading branch information
ashchan committed Mar 29, 2019
1 parent 0ecf783 commit 6a4f973
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Source/API/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ extension APIClient {
return try load(APIRequest<Header>(method: "get_tip_header"))
}

public func getCellsByTypeHash(typeHash: H256, from: BlockNumber, to: BlockNumber) throws -> [CellOutputWithOutPoint] {
return try load(APIRequest<[CellOutputWithOutPoint]>(method: "get_cells_by_type_hash", params: [typeHash, from, to]))
public func getCellsByLockHash(lockHash: H256, from: BlockNumber, to: BlockNumber) throws -> [CellOutputWithOutPoint] {
return try load(APIRequest<[CellOutputWithOutPoint]>(method: "get_cells_by_lock_hash", params: [lockHash, from, to]))
}

public func getLiveCell(outPoint: OutPoint) throws -> CellWithStatus {
Expand Down
6 changes: 3 additions & 3 deletions Source/Types/CellInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import Foundation

public struct CellInput: Codable, Param {
public let previousOutput: OutPoint
public let unlock: Script
public let args: [HexString]

enum CodingKeys: String, CodingKey {
case previousOutput = "previous_output"
case unlock
case args
}

public var param: [String: Any] {
return [
CodingKeys.previousOutput.rawValue: previousOutput.param,
"unlock": unlock.param
CodingKeys.args.rawValue: args
]
}
}
2 changes: 1 addition & 1 deletion Source/Types/CellOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct CellOutput: Codable, Param {
public let capacity: Capacity
public let data: HexString
public let lock: H256
public let lock: Script
public let type: Script?

public var param: [String: Any] {
Expand Down
14 changes: 8 additions & 6 deletions Tests/API/APIClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ class APIClientTests: XCTestCase {
XCTAssertTrue(result.number > 0)
}

func testGetCellsByTypeHash() throws {
func testGetCellsByLockHash() throws {
let client = APIClient()
let result = try client.getCellsByTypeHash(typeHash: "0x8954a4ac5e5c33eb7aa8bb91e0a000179708157729859bd8cf7e2278e1e12980", from: 1, to: 100)
let result = try client.getCellsByLockHash(lockHash: "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", from: 1, to: 100)
XCTAssertNotNil(result)
}

func testGetCurrentCell() throws {
func testGetLiveCell() throws {
let client = APIClient()
let cells = try client.getCellsByTypeHash(typeHash: "0x8954a4ac5e5c33eb7aa8bb91e0a000179708157729859bd8cf7e2278e1e12980", from: 1, to: 100)
let result = try client.getLiveCell(outPoint: cells.first!.outPoint)
XCTAssertNotNil(result)
let cells = try client.getCellsByLockHash(lockHash: "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", from: 1, to: 100)
if let cell = cells.first {
let result = try client.getLiveCell(outPoint: cell.outPoint)
XCTAssertNotNil(result)
}
}

func testGetTipBlockNumber() throws {
Expand Down

0 comments on commit 6a4f973

Please sign in to comment.