项目作者: fanquake

项目描述 :
Swift wrapper for the Bitcoin Core RPC
高级语言: Swift
项目地址: git://github.com/fanquake/CoreRPC.git
创建时间: 2018-09-15T06:25:21Z
项目社区:https://github.com/fanquake/CoreRPC

开源协议:

下载


CoreRPC

Swift wrapper for the Bitcoin Core RPC.

Build:

  1. swift build
  2. swift test
  3. # If you want an Xcode project
  4. swift package generate-xcodeproj

Add to your own project with:

  1. .package(url: "https://github.com/fanquake/CoreRPC", .branch("master"))
  1. import CoreRPC
  2. import PromiseKit
  3. let node = URL(string: "http://localhost:18332") // testnet
  4. let rpc = CoreRPC(url: node)
  5. firstly {
  6. rpc.getVerboseBlock(hash: "0000000014e6ae5aef5b7b660b160b7572fe14b95609fefb6f87c2d2e33a5fdd")
  7. }.done { block in
  8. print(block.confirmations, block.merkleroot)
  9. // 31165 "d20cdbe39d1528bacfab6f7a3c16d576aeae6e8fb993193692a918a7c5002450"
  10. let coinbase = block.tx.filter({ $0.isCoinbase() })
  11. print(coinbase.first!.txid)
  12. // "5b824f055bc4ea8763a817bd951c53f38f81d3c4f2066c6eee79acbad2819db7"
  13. }.catch { err in
  14. print(err)
  15. }

Configuration

The preferred configuration method is to set CORERPC_USER and CORERPC_PASS environment variables.

If found, they will be inserted into the given URL.

It is also possible to pass a fully formed URL, such as http://username:password@localhost:8332.

Swift Playground

An easy way to try this repo is with a Swift Playground.

  1. git clone https://github.com/fanquake/CoreRPC.git
  2. cd corerpc
  3. swift package generate-xcodeproj
  4. open CoreRPC.xcodeproj

Inside Xcode:

  • File -> New -> Playground
  • iOS (Blank) is fine.
  • Name the file Test.Playground and save it inside the corerpc directory.
    • Add to: CoreRPC
    • Group: CoreRPC
  • Create

Copy the following into the Playground:

  1. import CoreRPC
  2. import Foundation
  3. import PlaygroundSupport
  4. import PromiseKit
  5. PlaygroundPage.current.needsIndefiniteExecution = true

Then you can use as normal. i.e:

  1. let node = URL(string: "http://username:password@localhost:18332")!
  2. let rpc = try CoreRPC.init(url: node)
  3. firstly {
  4. rpc.getBlockHash(block: 554000)
  5. }.then { hash in
  6. rpc.getVerboseBlock(hash: hash)
  7. }.done { block in
  8. print("Tx count: \(block.tx.count)")
  9. }.catch { error in
  10. print(error)
  11. }

Playground

Testnet Block Explorer

An example block explorer application is available here.