# Migration de l’historique des transfers pour la migration en v2?

**URL:** https://forum.duniter.org/t/migration-de-l-historique-des-transfers-pour-la-migration-en-v2/12124
**Category:** Duniter-v2s
**Created:** [27 March 2024 19:15 UTC](https://forum.duniter.org/t/migration-de-l-historique-des-transfers-pour-la-migration-en-v2/12124 "2024-03-27T19:15:55Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [17 May 2024 09:46 UTC](https://forum.duniter.org/t/migration-de-l-historique-des-transfers-pour-la-migration-en-v2/12124/5 "2024-05-17T09:46:51Z")

</div>

J’ai pas mal avancé dessus et repris `py-g1-migrator` et le genesis `duniter-squid`. Voici des extraits de code pour ce qui touche aux transactions (les certifications c’est un peu plus compliqué) :

🔗 [lib/functions.py · ce8a73c7844cb04814246039dcc325d4a026239b · tools / py-g1-migrator · GitLab](https://git.duniter.org/tools/py-g1-migrator/-/blob/ce8a73c7844cb04814246039dcc325d4a026239b/lib/functions.py#L200-L244)

```python
def get_tx(leveldb_path: str) -> list:
    """
    Get tx,
    return a list of tx
    """
    # Get wallets balances data
    blocks_repo = LevelDBBlocksRepository(leveldb_path)
    txs = []
    for num, block in blocks_repo:
        if num % NOTIF_INTERVAL == 0:
            print(num)
        for tx in block.get("transactions"):
            outputs = tx["outputs"]
            issuers = tx["issuers"]
            comment = tx["comment"]
            timestamp = block["medianTime"]
            issuers_count = len(issuers)
            # loop on issuers. If multiple issuers, approximate amount
            for issuer in issuers:
                # loop on outputs
                for output in outputs:
                    outputparts = output.split(":")
                    amount = int(outputparts[0])
                    receiver = outputparts[2]
                    if issuers_count > 1:
                        amount = math.floor(amount / issuers_count) # approximation
                    # ignore non trivial unlock sources
                    # https://git.duniter.org/tools/py-g1-migrator/-/issues/3
                    if "&&" in receiver or "||" in receiver:
                        print(num)
                        print("ignoring " + receiver)
                        continue
                    receiver = receiver.split("SIG(")[1].split(")")[0]
                    sample = {
                        "blockNumber": num,
                        "timestamp": timestamp,
                        "from": issuer,
                        "to": receiver,
                        "amount": amount,
                        "comment": comment,
                    }
                    # do not include outputs that go back to sender
                    if sample["from"] != sample["to"]:
                        txs.append(sample)
    return txs

```

🔗 [src/genesis/genesis.ts · 7864398a48e981b53b8af5e709a6605b424998e7 · nodes / duniter-squid · GitLab](https://git.duniter.org/nodes/duniter-squid/-/blob/7864398a48e981b53b8af5e709a6605b424998e7/src/genesis/genesis.ts#L303-L326)

```js
// add txs
let genesis_tx_counter = 0;
for (const tx of tx_history) {
  // only older blocks
  if (tx.blockNumber > last_v1_block) continue
  // height conversion
  const negHeight = v1_to_v2(tx.blockNumber)
  // process
  genesis_tx_counter += 1;
  const date = new Date(tx.timestamp * 1000); // seconds to milliseconds
  const from = accounts.get(safePubkeyToAddress(tx.from));
  const to = accounts.get(safePubkeyToAddress(tx.to));
  genesis_transfers.push(
    new Transfer({
      id: `genesis-tx_n°${genesis_tx_counter}`,
      blockNumber: negHeight,
      timestamp: date,
      from,
      to,
      amount: BigInt(tx.amount),
      comment: tx.comment,
    })
  );
}

```

Les fichiers json seront fournis en assets GitLab sur la release.

Exemple de CI : [create\_g1\_data (#131675) · Jobs · nodes / rust / Duniter v2S · GitLab](https://git.duniter.org/nodes/rust/duniter-v2s/-/jobs/131675)

```auto
$ rm g1-dump.tgz
$ mv tmp/backup-g1-duniter-1.8.7 duniter_default
$ git clone https://git.duniter.org/tools/py-g1-migrator.git --depth 1 --branch hugo/docker /py-g1-migrator
Cloning into '/py-g1-migrator'...
$ cd /py-g1-migrator
$ ./main.py
Generate ĞTest genesis with up-to-date Ğ1 data
    dump ĞTest parameters...
    parse Identities...
    parse Wallets...
⚠️ wallet SIG(38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE) && SIG(GfKERHnJTYzKhKUma5h1uWhetbA8yHKymhVH2raf2aCP) ignored (balance 1002)
⚠️ wallet SIG(Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3P) && SIG(7F6oyFQywURCACWZZGtG97Girh9EL1kg2WBwftEZxDoJ) ignored (balance 103)
⚠️ initial monetary mass 9,173,584,257 does not equal wallet sum 9,173,554,151
money on the wallets: 9,173,553,046
money from ignored sources: 1,105
missing money (added to treasury): 30,106
    parse certifications...
    add simple wallets...
Done
$ ./squid-block.py
Prepare blocks for squid
0
100000
200000
300000
400000
500000
600000
700000
Exporting...
Done
$ ./squid-cert.py
Prepare cert for squid
0
100000
200000
300000
400000
500000
600000
700000
Exporting...
Done
$ ./squid-tx.py
Prepare tx for squid
0
100000
200000
300000
318637
ignoring SIG(CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW) || (SIG(CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd) && CSV(604800))
318637
ignoring SIG(CvrMiUhAJpNyX5sdAyZqPE6yEFfSsf6j9EpMmeKvMCWW) || (SIG(CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd) && CSV(604800))
365771
ignoring SIG(38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE) && SIG(GfKERHnJTYzKhKUma5h1uWhetbA8yHKymhVH2raf2aCP)
400000
409573
ignoring SIG(Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3P) && SIG(7F6oyFQywURCACWZZGtG97Girh9EL1kg2WBwftEZxDoJ)
500000
600000
700000
Exporting...
Done
$ mkdir -p $CI_PROJECT_DIR/release/
$ cp output/genesis.json $CI_PROJECT_DIR/release/
$ cp output/block_hist.json $CI_PROJECT_DIR/release/
$ cp output/cert_hist.json $CI_PROJECT_DIR/release/
$ cp output/tx_hist.json $CI_PROJECT_DIR/release/
Uploading artifacts for successful job 00:12
Uploading artifacts...
/builds/nodes/rust/duniter-v2s/release/: found 5 matching artifact files and directories 
g artifact files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created id=131675 responseStatus=201 Created token=glcbt-64
Cleaning up project directory and file based variables 00:01
Job succeeded

```

Et les artefacts : [release · Artifacts · create\_g1\_data (#131675) · Jobs · nodes / rust / Duniter v2S · GitLab](https://git.duniter.org/nodes/rust/duniter-v2s/-/jobs/131675/artifacts/browse/release/)

---

_[View the full topic](https://forum.duniter.org/t/migration-de-l-historique-des-transfers-pour-la-migration-en-v2/12124)._
