elements icon indicating copy to clipboard operation
elements copied to clipboard

Not aware of another node's issuance or reissuance unless you import address - add rpc importasset or similar?

Open wintercooled opened this issue 4 years ago • 1 comments

Unless you importaddress from any vout address used in the issuance or reissuance tx that another node made, your node is not aware of the issuance or reissuance, even if you have the asset in your wallet. This means that unless you import an address from the issuance you can't reissue (for example), even if it holds the relevant reissuance token.

Example:

  • e1 issues an asset that is reissuable

  • e1 send the reissuance token to e2

  • although it has the reissuance token e2 cannot reissue and gets the error: "Asset reissuance token definition could not be found in wallet."

  • currently, e2's only option is to importaddress for any of the vout addresses in the issuance tx. This imports as watch-only but is not ideal.

  • If e1 does not provide such an address to e2 then e2 can always get one by using the issuance txid (assuming that is known) and looking in getrawtransaction for any address in the vout section and using one of those. This requires that index=1 is set in the config.

After importing an address like this the asset issuance will show in listissuances and allow e2 to reissue the asset. The same thing happens if e2 reissues and e1 wants to see the reissuance in listissuances - e1 must import an address from the reissuance tx.

It would be nice to have an rpc command such as importasset, where an asset id is provided and the node is made aware of all issuances and reissuances for the asset. Not sure if that's possible or what constraints are placed on the node using it - must be indexed full node for example.

To see current behavior:

#!/bin/bash
set -x

shopt -s expand_aliases

alias e1-dae="/home/matthew/elements-0.18.1.6/bin/elementsd -datadir=$HOME/elementsdir1"
alias e1-cli="/home/matthew/elements-0.18.1.6/bin/elements-cli -datadir=$HOME/elementsdir1"

alias e2-dae="/home/matthew/elements-0.18.1.6/bin/elementsd -datadir=$HOME/elementsdir2"
alias e2-cli="/home/matthew/elements-0.18.1.6/bin/elements-cli -datadir=$HOME/elementsdir2"

# Ignore error
set +o errexit

e1-cli stop
e2-cli stop
sleep 5

rm -r ~/elementsdir1
rm -r ~/elementsdir2
mkdir ~/elementsdir1
mkdir ~/elementsdir2

cp ~/elements/contrib/assets_tutorial/elements1.conf ~/elementsdir1/elements.conf
cp ~/elements/contrib/assets_tutorial/elements2.conf ~/elementsdir2/elements.conf

e1-dae
e2-dae

sleep 5

until e1-cli getwalletinfo
do
  echo "Waiting for e1 to finish loading..."
  sleep 2
done

until e2-cli getwalletinfo
do
  echo "Waiting for e2 to finish loading..."
  sleep 2
done

ADDRGEN1=$(e1-cli getnewaddress)
ADDRGEN2=$(e2-cli getnewaddress)

e1-cli sendtoaddress $(e1-cli getnewaddress) 21000000 "" "" true
e1-cli generatetoaddress 101 $ADDRGEN1
sleep 5
e1-cli sendtoaddress $(e2-cli getnewaddress) 10500000 "" "" false
e1-cli generatetoaddress 101 $ADDRGEN1
sleep 5

e1-cli getwalletinfo
e2-cli getwalletinfo

# Unblinded issuance
# The same process works for blinded issuances as well
ISSUE=$(e1-cli issueasset 100 2 false)

ASSET=$(echo $ISSUE | jq '.asset' | tr -d '"')
ISSUE_TXID=$(echo $ISSUE | jq '.txid' | tr -d '"')
TOKEN=$(echo $ISSUE | jq '.token' | tr -d '"')
VIN=$(echo $ISSUE | jq '.vin' | tr -d '"')

e1-cli generatetoaddress 101 $ADDRGEN1
sleep 5

ISSUEADDR=$(e1-cli gettransaction $ISSUE_TXID | jq '.details[0].address' | tr -d '"')

e1-cli getwalletinfo
e2-cli getwalletinfo

e1-cli listissuances
# e2 doesn't know about the issuance:
e2-cli listissuances

# Send e2 the reissuance token
e1-cli sendtoaddress $(e2-cli getnewaddress) 1 "" "" false false 1 UNSET $TOKEN
e1-cli generatetoaddress 101 $ADDRGEN1
sleep 5

e1-cli getwalletinfo
# e2 has the reissuance token...
e2-cli getwalletinfo
# But e2 still doesn't know about the issuance:
e2-cli listissuances

# ... so e2's attempt to reissue will fail:
set +o errexit
REISSUE=$(e2-cli reissueasset $ASSET 99)


# Send e2 some of the asset
e1-cli sendtoaddress $(e2-cli getnewaddress) 1 "" "" false false 1 UNSET $ASSET
e1-cli generatetoaddress 101 $ADDRGEN1
sleep 5

# e2 has some of the asset...
e2-cli getwalletinfo
# But e2 still doesn't know about the issuance:
e2-cli listissuances


# So we need to import the address the asset was issued to into e2
# by getting the addresses issued to in the issuance tx.
trap read debug
e2-cli importaddress $ISSUEADDR 1

# Now e2 does know about the issuance:
e2-cli listissuances

# And can also reissue it:
REISSUE=$(e2-cli reissueasset $ASSET 99)
REISSUE_TXID=$(echo $REISSUE | jq '.txid' | tr -d '"')
REISSUEADDR=$(e2-cli gettransaction $REISSUE_TXID | jq '.details[0].address' | tr -d '"')

e2-cli generatetoaddress 101 $ADDRGEN1
sleep 5

e1-cli getwalletinfo
e2-cli getwalletinfo

# e1 doesn't know about the reissuance:
e1-cli listissuances
# E2 does because it did the reissuance:
e2-cli listissuances

# So we need to import the address from the reissuer (e2) into e1 as a watch only address:
e1-cli importaddress $REISSUEADDR 1
# e1 can now see the reissuance:
e1-cli listissuances

e1-cli stop
e2-cli stop

wintercooled avatar Apr 22 '20 13:04 wintercooled

Should we have a a command importcontract to make possible to make reissuance from asset issued somewhere else?

tiero avatar Dec 23 '21 17:12 tiero