atomicals / atomicals-electrumx

Electrumx Atomicals Indexer Server
MIT License
187 stars 55 forks source link

[Split] partially colored #161

Closed shadowv0vshadow closed 6 months ago

shadowv0vshadow commented 7 months ago

Here are some examples for partially colored:

1. Fulled colored -> Partially colored example:
Vin[0]: 1000 Satoshis (colored with 1000 Atoms)
Vin[1]: 99999999999900 Satoshis

Vout[0]: 900 Satoshis (colored with 900 Atoms)
Vout[1]: 100000000000000 Satoshis (colored with 100 Atoms)
2. Partially colored ->  Fulled colored example:
Vin[0]: 1000 Satoshis (colored with 100 Atoms)
Vin[1]: 1000 Satoshis (colored with 900 Atoms)

Vout[0]: 1000 Satoshis (colored with 1000 Atoms)
Vout[1]: 1000 Satoshis (colored with 0 Atoms)
3. Split 1 token example:
Vin[0]: 1000 Satoshis (colored with 1000 Atoms)
Vin[1]:  546 Satoshis

Vout[0]: 999 Satoshis (colored with 999 Atoms)
Vout[1]: 547 Satoshis (colored with 1 Atoms)
4. Multiple Partially colored example:
Vin[0]: 1000 Satoshis (colored with 1000 Atoms and 1000 quarks)
Vin[1]: 900 Satoshis

Vout[0]: 900 Satoshis (colored with 900 Atoms and 900 quarks)
Vout[1]: 1000 Satoshis (colored with 100 Atoms and 100 quarks)
shadowv0vshadow commented 7 months ago

This PR will activate on a specific height for the partial coloring feature, which allows the minimum coloring to be 1. This split does't involve fractional splitting. By using partial coloring, tokens can be split into a minimum of 1. This is sufficient for current needs. For partially colored UTXOs, merging will be attempted during transfer, using a FIFO for colored UTXOs. It only applies to Fungible Tokens (FTs) and doesn't apply to Non-Fungible Tokens (NFTs).

hotbroker commented 7 months ago

image typo?

shadowv0vshadow commented 7 months ago

Migration guide

1. API change

blockchain.scripthash.listunspent

FROM:

{
  "txid": "1f5db4cb0c72546cea7a027c403adda96767f0d6e45e75c237fc085a56eb29d7",
  "tx_hash": "1f5db4cb0c72546cea7a027c403adda96767f0d6e45e75c237fc085a56eb29d7",
  "index": 0,
  "tx_pos": 0,
  "vout": 0,
  "height": 2541154,
  "value": 1000,
  "atomicals": ["45515640773c53609a92a1023359bf9a0f864f8f8454c62f58682b3145a9a043i0"]
}

TO

{
  "txid": "1f5db4cb0c72546cea7a027c403adda96767f0d6e45e75c237fc085a56eb29d7",
  "tx_hash": "1f5db4cb0c72546cea7a027c403adda96767f0d6e45e75c237fc085a56eb29d7",
  "index": 0,
  "tx_pos": 0,
  "vout": 0,
  "height": 2541154,
  "value": 1000,
  "satvalue": 1000,
  "atomicals": {
      "45515640773c53609a92a1023359bf9a0f864f8f8454c62f58682b3145a9a043i0": 1000
  }
}

We must use the value in atomicals, It represents the actual value of this FT, and in some partially colored cases, the value of this FT may differ from the satoshi value of this UTXO.

We have retained the 'value' field for transitional adjustments. We will remove the 'value' field in subsequent updates to avoid unnecessary confusion.

blockchain.atomicals.listscripthash

The modifications are the same as those for blockchain.scripthash.listunspent, both targeting the atomicals field.

blockchain.scripthash.listunspent

The return content remains the same, it is important to note that the confirmed value now also represents the actual partially colored value.

blockchain.atomicals.get_ft_balances_scripthash

The return content remains the same, it is important to note that the confirmed value now also represents the actual partially colored value.

For example:

{
  "success": true,
  "response": {
    "balances": {"595522d778ec1f40e3068553ef5aef0ccb52c502786496c0882bb79818fa6db2i0": {
        "id": "595522d778ec1f40e3068553ef5aef0ccb52c502786496c0882bb79818fa6db2i0",
        "ticker": "amt",
        "confirmed": 1
      }
    }
  }
}

2. The partial coloring feature requires reindexing.

3. We have removed the validation check for 'cleanly_assigned' from blockchain.atomicals.validate and blockchain.transaction.broadcast. This is done to allow the partial coloring code to run more smoothly.

atomicals commented 7 months ago

This is very well done and thought out, thank you!

hotbroker commented 7 months ago

交易所和钱包的balance都沟通同步支持了吧?