-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
from . import config | ||
from . import core | ||
from . import ripemd160 | ||
from . import rpc | ||
from . import secp256k1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import btc | ||
import random | ||
import requests | ||
import typing | ||
|
||
|
||
def call(method: str, params: typing.List[typing.Any]) -> typing.Any: | ||
r = requests.post(btc.config.current.rpc.addr, json={ | ||
'id': random.randint(0x00000000, 0xffffffff), | ||
'jsonrpc': '2.0', | ||
'method': method, | ||
'params': params, | ||
}, auth=( | ||
btc.config.current.rpc.username, | ||
btc.config.current.rpc.password, | ||
)).json() | ||
if 'error' in r and r['error']: | ||
raise Exception(r['error']) | ||
return r['result'] | ||
|
||
|
||
def generate_to_address(nblocks: int, address: str) -> typing.List[bytearray]: | ||
r = call('generatetoaddress', [nblocks, address]) | ||
return [bytearray.fromhex(e) for e in r] | ||
|
||
|
||
def get_block_count() -> int: | ||
return call('getblockcount', []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import btc | ||
|
||
|
||
def test_get_block_count(): | ||
btc.config.current = btc.config.develop | ||
assert btc.rpc.get_block_count() != 0 |