CoreRPC
所属分类:加密货币
开发工具:Swift
文件大小:470KB
下载次数:0
上传日期:2021-12-27 14:20:09
上 传 者:
sh-1993
说明: 比特币核心RPC的Swift包装器
(Swift wrapper for the Bitcoin Core RPC)
文件列表:
Example (0, 2020-06-15)
Example\Package.swift (567, 2020-06-15)
Example\Sources (0, 2020-06-15)
Example\Sources\Application (0, 2020-06-15)
Example\Sources\Application\Application.swift (1645, 2020-06-15)
Example\Sources\Explorer (0, 2020-06-15)
Example\Sources\Explorer\main.swift (133, 2020-06-15)
Package.swift (538, 2020-06-15)
Sources (0, 2020-06-15)
Sources\CoreRPC (0, 2020-06-15)
Sources\CoreRPC\Blockchain.swift (5355, 2020-06-15)
Sources\CoreRPC\CoreRPC.swift (3199, 2020-06-15)
Sources\CoreRPC\Descriptor.swift (925, 2020-06-15)
Sources\CoreRPC\ErrorCodes.swift (3035, 2020-06-15)
Sources\CoreRPC\Fees.swift (924, 2020-06-15)
Sources\CoreRPC\Labels.swift (298, 2020-06-15)
Sources\CoreRPC\MemPool.swift (1389, 2020-06-15)
Sources\CoreRPC\Methods.swift (2317, 2020-06-15)
Sources\CoreRPC\Mining.swift (1288, 2020-06-15)
Sources\CoreRPC\Network.swift (3713, 2020-06-15)
Sources\CoreRPC\PSBT.swift (936, 2020-06-15)
Sources\CoreRPC\Proof.swift (549, 2020-06-15)
Sources\CoreRPC\SoftFork.swift (1255, 2020-06-15)
Sources\CoreRPC\Stats.swift (2840, 2020-06-15)
Sources\CoreRPC\Transaction.swift (6787, 2020-06-15)
Sources\CoreRPC\Utility.swift (3895, 2020-06-15)
Sources\CoreRPC\Wallet.swift (5376, 2020-06-15)
Sources\CoreRPC\ZeroMQ.swift (522, 2020-06-15)
Tests (0, 2020-06-15)
Tests\CoreRPCTests (0, 2020-06-15)
Tests\CoreRPCTests\CoreRPCTests.swift (194, 2020-06-15)
Tests\CoreRPCTests\XCTestManifests.swift (144, 2020-06-15)
Tests\LinuxMain.swift (115, 2020-06-15)
playground.png (467936, 2020-06-15)
# CoreRPC
Swift wrapper for the [Bitcoin Core](https://github.com/bitcoin/bitcoin) [RPC](https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs).
Build:
```bash
swift build
swift test
# If you want an Xcode project
swift package generate-xcodeproj
```
Add to your own project with:
```swift
.package(url: "https://github.com/fanquake/CoreRPC", .branch("master"))
```
```swift
import CoreRPC
import PromiseKit
let node = URL(string: "http://localhost:18332") // testnet
let rpc = CoreRPC(url: node)
firstly {
rpc.getVerboseBlock(hash: "0000000014e6ae5aef5b7b660b160b7572fe14b95609fefb6f87c2d2e33a5fdd")
}.done { block in
print(block.confirmations, block.merkleroot)
// 31165 "d20cdbe39d1528bacfab6f7a3c16d576aeae6e8fb993193692a918a7c5002450"
let coinbase = block.tx.filter({ $0.isCoinbase() })
print(coinbase.first!.txid)
// "5b824f055bc4ea8763a817bd951c53f38f81d3c4f2066c6eee79acbad2819db7"
}.catch { err in
print(err)
}
```
### 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](https://developer.apple.com/swift-playgrounds).
```bash
git clone https://github.com/fanquake/CoreRPC.git
cd corerpc
swift package generate-xcodeproj
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:
```swift
import CoreRPC
import Foundation
import PlaygroundSupport
import PromiseKit
PlaygroundPage.current.needsIndefiniteExecution = true
```
Then you can use as normal. i.e:
```swift
let node = URL(string: "http://username:password@localhost:18332")!
let rpc = try CoreRPC.init(url: node)
firstly {
rpc.getBlockHash(block: 554000)
}.then { hash in
rpc.getVerboseBlock(hash: hash)
}.done { block in
print("Tx count: \(block.tx.count)")
}.catch { error in
print(error)
}
```
![Playground](playground.png)
## Testnet Block Explorer
An example block explorer application is available [here](Example/README.md).
近期下载者:
相关文件:
收藏者: