Ejemplo n.º 1
0
    bitcoin.generate(101)
    sidechain.generate(101)

    addr = bitcoin.getnewaddress()

    addrs = sidechain.getpeginaddress()
    txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24)
    # 10+2 confirms required to get into mempool and confirm
    bitcoin.generate(11)
    time.sleep(2)
    proof = bitcoin.gettxoutproof([txid1])
    raw = bitcoin.getrawtransaction(txid1)

    print("Attempting peg-in")
    try:
        pegtxid = sidechain.claimpegin(raw, proof)
        raise Exception(
            "Peg-in should not mature enough yet, need another block.")
    except JSONRPCException as e:
        assert (
            "Peg-in Bitcoin transaction needs more confirmations to be sent."
            in e.error["message"])
        pass

    # Should fail due to non-matching wallet address
    try:
        pegtxid = sidechain.claimpegin(raw, proof, sidechain.getnewaddress())
        raise Exception("Peg-in with non-matching claim_script should fail.")
    except JSONRPCException as e:
        assert (
            "Given claim_script does not match the given Bitcoin transaction."
Ejemplo n.º 2
0
sidechain.generate(101)

addr = bitcoin.getnewaddress()

# Lockup some funds to unlock later
sidechain.sendtomainchain(addr, 50)
sidechain.generate(101)

addrs = sidechain.getpeginaddress()
txid = bitcoin.sendtoaddress(addrs["mainchain_address"], 49)
bitcoin.generate(10)
proof = bitcoin.gettxoutproof([txid])
raw = bitcoin.getrawtransaction(txid)

print("Attempting peg-in")
pegtxid = sidechain.claimpegin(addrs["sidechain_address"], raw, proof)
sidechain.generate(1)

tx = sidechain.gettransaction(pegtxid)

if "confirmations" in tx and tx["confirmations"] > 0:
    print("Peg-in is confirmed: Success!")
else:
    print("Peg-in has failed.")

print("Stopping daemons and cleaning up")
bitcoin.stop()
sidechain.stop()

time.sleep(5)