Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: implement create_deposit_transaction #60

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

torkelrogstad
Copy link
Contributor

@torkelrogstad torkelrogstad commented Oct 23, 2024

This is currently not working.

~I'm not sure how to add the previous Ctip to the OP_DRIVECHAIN TX. I'm using add_foreign_utxo, but don't know how to obtain the psbt_input and satisfaction_weight values to pass in as parameters to that method. ~

I'm able to create a transaction, but having some issues with both broadcasting as well as adding the previous Ctip for the sidechain.

Update: was able to broadcast the TX, with help from @CryptAxe . Was missing the acceptnonstdtxn parameter for my local Core node. Updated the README.

Example of a created transaction:

01000000000101516a86d7e375cd3295288eaed9b691734e5a218e7e02c99fff6e8196977b84b40100000000feffffff030000000000000000086a06666f6f626172d20400000000000004b4010051a114f505000000001600144d5107fd06c1935a71774c597e75f559def104c502473044022064fedbef71712c56a49449c61e84d97d80dd29501aa1ac8cac3ac8d6ecca4be9022015bf7c74b97463a10ddca461cc7155208a351b4f9a0a47e6fb153ac4bc46a479012103355f95c00c42a6f5211336d22b8a34e121b9bbdf79f0e9e8cab5479835e59f5b6b860000

This decodes to:

{
  "txid": "e384460220fd04348d2b74488710d2f3ffd772332aa3be9662f62a18f80f9aaf",
  "hash": "ed8449eb824f6f9629a9a4567faefde782140cc9c7aae8a8e6eda00af3052747",
  "version": 1,
  "size": 221,
  "vsize": 140,
  "weight": 557,
  "locktime": 34411,
  "vin": [
    {
      "txid": "b4847b9796816eff9fc9027e8e215a4e7391b6d9ae8e289532cd75e3d7866a51",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "3044022064fedbef71712c56a49449c61e84d97d80dd29501aa1ac8cac3ac8d6ecca4be9022015bf7c74b97463a10ddca461cc7155208a351b4f9a0a47e6fb153ac4bc46a47901",
        "03355f95c00c42a6f5211336d22b8a34e121b9bbdf79f0e9e8cab5479835e59f5b"
      ],
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 666f6f626172",
        "desc": "raw(6a06666f6f626172)#jpksrptg",
        "hex": "6a06666f6f626172",
        "type": "nulldata"
      }
    },
    {
      "value": 0.00001234,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_NOP5 0 1",
        "desc": "raw(b4010051)#zv47nv5u",
        "hex": "b4010051",
        "type": "nonstandard"
      }
    },
    {
      "value": 0.99947681,
      "n": 2,
      "scriptPubKey": {
        "asm": "0 4d5107fd06c1935a71774c597e75f559def104c5",
        "desc": "addr(tb1qf4gs0lgxcxf45uthf3vhua04t800zpx9genuwr)#3gxj5n9e",
        "hex": "00144d5107fd06c1935a71774c597e75f559def104c5",
        "address": "tb1qf4gs0lgxcxf45uthf3vhua04t800zpx9genuwr",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}

src/wallet/mod.rs Outdated Show resolved Hide resolved
@nchashch
Copy link
Collaborator

In the bip300301_wallet implementation add_foreign_utxo works like this:

            builder
                .add_foreign_utxo(
                    ctip_outpoint,
                    bitcoin::psbt::Input {
                        non_witness_utxo: Some(transaction),
                        ..bitcoin::psbt::Input::default()
                    },
                    0,
                )
                .into_diagnostic()?;

@nchashch
Copy link
Collaborator

I am not sure how to get the value for satisfaction_weight either.

Here is the documentation for the function:

https://docs.rs/bdk/latest/bdk/wallet/tx_builder/struct.TxBuilder.html#method.add_foreign_utxo

satisfaction_weight: To know how much weight/vbytes the input will add to the transaction for fee calculation.

If I understand this correctly it is the weight of the script that will satisfy the scriptPubKey of the input.

The treasury UTXO is an anyone can spend, so I think setting satisfaction_weight to 0 would make sense. It did work for bip300301_wallet implementation, though it would make sense to double check this, or at least add a comment like "// Setting this to 0 might be wrong".

@torkelrogstad
Copy link
Contributor Author

Thanks @nchashch! Appreciate it

@nchashch
Copy link
Collaborator

Thanks @nchashch! Appreciate it

Here is the actual implementation in bip300301_wallet:

https://github.com/LayerTwo-Labs/bip300301_wallet/blob/master/src/wallet.rs#L749

@torkelrogstad torkelrogstad force-pushed the 2024-10-23-deposit-tx branch 2 times, most recently from 7e8050e to 41acae3 Compare October 29, 2024 14:18
@torkelrogstad torkelrogstad marked this pull request as ready for review October 29, 2024 14:18
src/convert.rs Outdated Show resolved Hide resolved
src/convert.rs Outdated Show resolved Hide resolved
src/convert.rs Outdated Show resolved Hide resolved
src/convert.rs Outdated Show resolved Hide resolved
src/convert.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
@Ash-L2L Ash-L2L merged commit 3c85e8f into LayerTwo-Labs:master Oct 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants