RGB-WG / rgb

RGB smart contracts: command-line tool & wallet runtime library for desktop and mobile integration
https://rgb.tech
Apache License 2.0
140 stars 36 forks source link

Fungible asset allocation history information not extracted successfully #237

Closed k0k0ne closed 2 months ago

k0k0ne commented 2 months ago

RGB version

0.11.0-beta.7

Reproduction Steps

Just follow the standard procedure to issue assets and query state.

Observed Behavior

Fungible asset allocation information is not visible.

Seems the function contract.fungible(owned.name.clone(), &filter) returns an empty value.

Additional Details

I tried to set some breakpoints.

#[inline]
fn fungible_all(&self) -> impl Iterator<Item = &OutputAssignment<RevealedValue>> {
    self.unfiltered
        .borrow()
        .fungibles
        .iter()
        .filter(|assignment| assignment.check_witness(&self.filter))
}

The assignment.check_witness function is executed once, indicating that self.unfiltered contains data. It can be observed that assignment.check_witness returns true.

However, in the include_outpoint function in src/wrapper.rs, XChain::Bitcoin(outpoint) has a txid of 1f8aed3292b0d1418171f5da7903ad635baa7aae6be4aedd1ac88dfbc9a8a2a9, while *output has a txid of 311ec7d43f0f33cda5a0c515a737b5e0bbce3896e6eb32e67db0e868a58f4150. This discrepancy might cause the filter to return false, ultimately resulting in no data being displayed.

When issuing, I have:

let beneficiary_txid = Txid::from_hex("44763b5d58ca6a750184d13a5a82e879435e2865906652943c25a40937252bd5")

However, in cache.yaml of wallet, it is:

tx:
  1f8aed3292b0d1418171f5da7903ad635baa7aae6be4aedd1ac88dfbc9a8a2a9

I am unsure why these two are inconsistent.

dr-orlovsky commented 2 months ago

@zoedberg @nicbus do you have tests covering such a case and do they succeed with the latest master?

dr-orlovsky commented 2 months ago

@k0k0ne but does 44763b5d58ca6a750184d13a5a82e879435e2865906652943c25a40937252bd5, the transaction with the output to which you assign the issued asset, belongs to your wallet?

If you want to see all fungible state, not just the one for your wallet, you have to use FilterAll as a filter, instead of your wallet.filter().

nicbus commented 2 months ago

Interpreting "standard procedure to issue assets and query state" as "using the CLI" and with rgb-sandbox updated to use bp-wallet, rgb-wallet and rgb-schemata all at version 0.11.0-beta.7, I can successfully issue an asset and then see the allocation in the contract state.

Here the relevant commands and related output:

$ rgb -n regtest --electrum=localhost:50001 -d data0 issue -w wallet_0 'RDYhMTR!9gv8Y2GLv9UNBEK1hcrCmdLDFk9Qd5fnO8k#brave-dinner-banana' ssi:wallet_0 contracts/usdt.yaml

A new contract rgb:aRxk1nph-LLGKNzR-WWYq7U8-7fo5FkS-eJzbBAc-NQDhBac is issued and added to the stash.
$ rgb -n regtest --electrum=localhost:50001 -d data0 state -w wallet_0 rgb:aRxk1nph-LLGKNzR-WWYq7U8-7fo5FkS-eJzbBAc-NQDhBac RGB20Fixed

Global:                                                                                                                                                                                                                                                                                   
  spec := (ticker=("USDT"), name=("USD Tether"), details=~, precision=0)
  terms := (text=("demo NIA asset"), media=~)
  issuedSupply := (2000)

Owned:
  assetOwner:
    value=2000, utxo=bc:opret1st:3ba030f10013b87eaf4631949c7a52837ad8ee26dd2044c4832eed151ee87d2d:1, witness=~ 

The assignments -> assetOwner -> seal in the contract's yaml is set to an UTXO controlled by the wallet (on keychain 9 or 10, based on the closing method).

After this, I can successfully spend the asset and the contract state continues to be the expected one.

k0k0ne commented 2 months ago

Thank you for your reply. It's working now.