예제 #1
0
## 5. Multi-asset support
#
# Many of the RPC calls have added asset type or label arguments, and reveal
# alternative asset information. With no argument all are listed. For example,
# try `getwalletinfo` or `getbalance`. (Notice in the above code our assertions
# have taken forms like {"bitcoin": 100} rather than bare numbers.)
#
# Notice we now see "bitcoin" as an asset. This is the asset label for the hex
# for "bitcoin" which can be discovered using the `dumpassetlabels` RPC. We
# can see more details of each issuance that your wallet knows about with the
# `listissuances` RPC. Initially there is only one asset, "bitcoin", and one
# issuance (the initial issuance).
print("")
print("5. Multi-asset support")
print("Existing assets: ", e1.dumpassetlabels())
assert len(e1.dumpassetlabels()) == 1
assert len(e1.listissuances()) == 1
assert e1.listissuances()[0]['assetlabel'] == "bitcoin"
assert e1.listissuances(
)[0]['assetamount'] == 21000000  # 21M initial free coins
assert e1.listissuances()[0]['tokenamount'] == 0  # no reissuance tokens
assert e1.dumpassetlabels() == e2.dumpassetlabels()

print("5a. Issue a new asset, with reissuance token")
# We can also issue our own assets, 1 asset and 1 reissuance token in this case
issue = e1.issueasset(1, 1)
asset = issue["asset"]

# From there you can look at the issuances you have in your wallet
assert len(e1.listissuances()) == 2
예제 #2
0
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"])
sync_all([alice, carol])
alice.generatetoaddress(1, alice.getnewaddress())
sync_all([alice, carol])

# Define some variables and continue..
asset_ALT = issue["asset"]
asset_BTC = alice.dumpassetlabels()["bitcoin"]

assert len(alice.listunspent()) > 0
assert len(carol.listunspent()) > 0

## 2. Construct a swap transaction in PSET format
#
# At this point node `alice` has 10.5MM "bitcoin" and node `carol` has 1000 of
# a new asset. We want to do an atomic swap: 2500 BTC for 1000 of
# the new asset.
#
print ("2. Create an unsigned swap transaction in PSET format.")

#
# Although PSBT2 was designed with coinjoining in mind, the RPC interface
# currently does not support iteratively creating a transaction. So we must