Example #1
0
assert e1.getwalletinfo()['balance'] == {'bitcoin': 0}
e1.rescanblockchain()
e2.rescanblockchain()
assert e1.getwalletinfo()['balance'] == {'bitcoin': 21000000}
assert e2.getwalletinfo()['balance'] == {'bitcoin': 21000000}
# All the initial coins coins are in one UTXO
assert len(e1.listunspent()) == 1
# ...and both nodes think they own it. This is a common situation when
# using near-empty test chains, so be aware of it.
assert e1.listunspent() == e2.listunspent()

# Generate 10 blocks to demonstrate how block generation work. On our test chain,
# each block has a subsidy of zero (this can be changed with `con_blocksubsidy`)
# and sends the coins to an OP_TRUE output (this script can be changed with
# the `-signblockscript` config).
e1.generatetoaddress(10, e1.getnewaddress())
# The wallet does not recognize zero-valued outputs as being owned
assert len(e1.listunspent()) == 1
assert e1.getwalletinfo()['balance'] == {'bitcoin': 21000000}

# Synchronize the chains
sync_all([e1, e2])
assert e1.getblockcount() == 10
assert e1.getbestblockhash() == e2.getbestblockhash()

## 2. Basic wallet usage
print("")
print("2. Basic wallet usage")

# 2a. Send all the coins to e1
#     Observe that this address is a confidential address (is much longer
Example #2
0
# 1a. Turn on both nodes. Disable -validatepegin as we will just swap the
#     initialcoins asset with a newly issued asset. Using the peg would
#     be an inessential distraction.
#
alice.start(["-validatepegin=0"])
carol.start(["-validatepegin=0"])
alice.connect_to(carol)
carol.connect_to(alice)
alice.createwallet("wallet")
carol.createwallet("wallet")
alice.rescanblockchain()

# 1b. Split the initial coins so that both sides have some (but Alice has more)
alice.sendmany("", { alice.getnewaddress(): 10000 for x in range(0, 10) })
alice.sendtoaddress(carol.getnewaddress(), 100000)
alice.generatetoaddress(1, alice.getnewaddress())

# 1c. Issue 1000 units of a new asset. No reissuance tokens. Send them
#     all to the second node.
issue = alice.issueasset(1000, 0)
alice.sendtoaddress(address=carol.getnewaddress(), amount=1000, assetlabel=issue["asset"])
alice.generatetoaddress(1, alice.getnewaddress())
sync_all([alice, carol])

# 1d. Move the coins around on each wallet so that they do not share
#     any wallet transaction. (Otherwise they may fill in each others'
#     UTXO data, which is harmless but makes the tutorial harder to
#     follow.)
alice.sendtoaddress(alice.getnewaddress(), alice.getbalance()["bitcoin"], "", "", True)
carol.sendtoaddress(carol.getnewaddress(), carol.getbalance()["bitcoin"], "", "", True)
carol.sendtoaddress(address=carol.getnewaddress(), amount=1000, assetlabel=issue["asset"])