Esempio n. 1
0
def list_nodes():
    nodes = []
    rpc = BitcoinRPC(
        user='******',
        passwd='python',
        host='127.0.0.1',
        port=18332,
    )
    try:
        response = rpc.getblockchaininfo()
        nodes.append(Node(online=True))
    except Exception as e:
        nodes.append(Node(online=False))
    return nodes
Esempio n. 2
0
def run():
    rpc = BitcoinRPC('localhost', 22555, settings["user"], settings["pass"])

    with io.open(settings['combined']) as f:
        s = f.read()

    for tx in s.split('\n'):
        if len(tx) > 0:
            sendTx(rpc, tx)
Esempio n. 3
0
def run(user, passwd, start, num):
  h = None

  rpc = BitcoinRPC('localhost', 22555, user, passwd)
  reply = rpc.execute([rpc.build_request(0, 'getblockhash', [start])]);

  for resp_obj in reply:
      if rpc.response_is_error(resp_obj):
        print('JSON-RPC: error at getblockhash for block ' + start, file=sys.stderr)
        exit(1)
      h = resp_obj['result']

  counter = SigCounter()
  check = lambda b: parseAndCount(counter, b)

  for i in range(0, num):
    h = fetch_block(rpc, h, check)
    if i % 1000 == 999:
      counter.report()

  counter.report()
Esempio n. 4
0
def run():
    rpc = BitcoinRPC('localhost', 22555, settings["user"], settings["pass"])

    maxconf = getCurrentHeight(rpc)
    minconf = maxconf - MAXBLOCK

    utxoset = getUtxo(rpc, minconf, maxconf)
    sortedset = sorted(utxoset, key=sortutxo)
    candidates = createCandidates(sortedset)

    for c in candidates:
        c.createBareTx()

    print("\n".join(map(lambda x: x.bare.as_hex(), candidates)))
Esempio n. 5
0
from rpc import BitcoinRPC
from decimal import Decimal

bitcoind = BitcoinRPC('naituida', '123', 'localhost', 8088)

GENESIS_ADDR = "FoipmNrZ5wARHJoszB4ZDHMoVtZ1TCSy2K"

START_BLOCK = 0
END_BLOCK = 1000

for blockheight in xrange(START_BLOCK, END_BLOCK):
    blockhash = bitcoind.getblockhash(blockheight)
    #    print blockhash
    block = bitcoind.getblock(blockhash)
    #    print block
    txs = block['tx']
    for txid in txs:
        tx = bitcoind.getrawtransaction(txid)
        raw_tx = bitcoind.decoderawtransaction(tx)
        outputs = raw_tx['vout']
        for output in outputs:
            addr = output['scriptPubKey']['addresses'][0]
            if addr == GENESIS_ADDR:
                print txid
Esempio n. 6
0
from sanic import Sanic
from sanic.response import file
from sanic.websocket import WebSocketProtocol
from sanic_graphql import GraphQLView

from graphql_ws.websockets_lib import WsLibSubscriptionServer

from rpc import BitcoinRPC
from gql import schema

hwi_lock = asyncio.Lock()
app = Sanic()
CORS(app, automatic_options=True)
rpc = BitcoinRPC(
    user='******',
    passwd='python',
    host='127.0.0.1',
    port=18332,
)


async def hwi_enumerate():
    async with hwi_lock:
        return commands.enumerate()


@app.websocket('/devices')
async def list_devices(request, ws):
    while True:
        devices = await hwi_enumerate()
        await ws.send(json.dumps(devices))
        await asyncio.sleep(1)
Esempio n. 7
0
from rpc import BitcoinRPC
from decimal import Decimal

bitcoind = BitcoinRPC('naituida','123','localhost',8088)
#print bitcoind.getinfo()

def send_from_local(from_addresses, payments, change_address, min_conf=0, wallet_pwd=None):
    _payments = {}
    for address, amount in payments.iteritems():
        _payments[address] = Decimal(amount)
    payments = _payments

    fee = bitcoind.getinfo()['paytxfee']

    unspent = [t for t in bitcoind.listunspent(minconf = min_conf) if t['address'] in from_addresses]

    send_sum = sum(payments.values())
    unspent_sum = sum([t['amount'] for t in unspent])

    if unspent_sum < send_sum + fee:
        print "Not enough fund!"
        exit()

    #select unspent
    unspent.sort(key=lambda t: t['confirmations'], reverse=True)

    chosen = []
    for t in unspent:
        if sum([c['amount'] for c in chosen]) < send_sum + fee:
            chosen.append(t)
        else:
Esempio n. 8
0
from rpc import BitcoinRPC
from decimal import Decimal

bitcoind = BitcoinRPC('naituida','123','localhost',8088)

GENESIS_ADDR = "FoipmNrZ5wARHJoszB4ZDHMoVtZ1TCSy2K"

START_BLOCK = 0
END_BLOCK = 1000

for blockheight in xrange(START_BLOCK,END_BLOCK):
    blockhash = bitcoind.getblockhash(blockheight)
#    print blockhash
    block = bitcoind.getblock(blockhash)
#    print block
    txs = block['tx']
    for txid in txs:
        tx = bitcoind.getrawtransaction(txid)
        raw_tx = bitcoind.decoderawtransaction(tx)
        outputs = raw_tx['vout']
        for output in outputs:
            addr =  output['scriptPubKey']['addresses'][0]
            if addr == GENESIS_ADDR:
                print txid