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

feat: Support open transaction operation #37

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
09e5751
feat: 🎸 Add functions to read transaction data and hash
Oct 5, 2022
c0514f1
feat: 🎸 add function to assemble multiple opentx to a tx
Oct 10, 2022
d33a21f
test: 💍 Add example to test opentx build
Oct 13, 2022
e3b4138
feat: 🎸 Can sign PubkeyHash opentx transaction
Oct 13, 2022
f5ee456
test: 💍 Add command to add input/output for opentx
Oct 14, 2022
5beb844
feat: 🎸 OpenTx sign PubkeyHash ready
Oct 18, 2022
0b16ce7
test: 💍 Fix opentx example by add sighash dep
Oct 18, 2022
08f3f6b
feat: 🎸 sign for openx ethereum/multisig
Oct 20, 2022
a10a58d
test: 💍 example about opentx ethereum
Oct 20, 2022
21c9a53
feat: 🎸 Finish example about opentx/multisig
Oct 24, 2022
1f0f95e
docs: ✏️ complete docs about opentx/multisig example
Oct 24, 2022
e81a357
feat: 🎸 can put multi opentxes into one open transaction
Oct 24, 2022
3e0805d
fix: 🐛 fix compile problems after merge from master
Oct 25, 2022
3bb4ea3
docs: ✏️ Move the big docs from source file to another doc
Nov 1, 2022
348b8d9
style: 💄 make code more readable
Nov 1, 2022
2c7add3
test: 💍 Add tests about opentx simple hash transfer
Nov 2, 2022
a15938a
test: 💍 Add test about opentx simple multisig transfer
Nov 2, 2022
a3e869c
test: 💍 Tests with index opentx input to end a transaction
Nov 3, 2022
a204551
test: 💍 Add test about multisig opentx test case
Nov 7, 2022
56cd5f2
test: 💍 Add test about open transaction buy udt
Nov 8, 2022
840f9d7
fix: 🐛 fix compile error after rebase master branch
Nov 8, 2022
65c3c62
chore: 🤖 Add Err for not configure open transaction list
Nov 18, 2022
65750b8
chore: 🤖 Remove unnecessary output and add comments
Nov 18, 2022
0337564
fix: 🐛 Handle opentx scriptgroup for merge
Nov 21, 2022
860aa19
chore: 🤖 Fix document typo
Nov 30, 2022
40ed79d
use last version for open tx.
EthanYuan Dec 7, 2022
3c1503a
follow the Omni lock CellMask definition adjust
EthanYuan Dec 7, 2022
6f1c17d
Merge pull request #1 from EthanYuan/opentx_sign_tx
Dec 7, 2022
379c84c
feat: 🎸 Use modified balancer to replace tmp opentx output
Dec 8, 2022
e540e16
docs: ✏️ Add changes into CHANGELOG.md
Dec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 2.4.0
* **BREAKING CHANGE**: add parameter `tx_dep_provider: &dyn TransactionDependencyProvider` to `ScriptSigner::sing_tx`.
* Support open transaction.

# 2.3.0
* Update ckb to v0.105.1
* **BREAKING CHANGE**: `get_transaction` rpc now return `TransactionWithStatusResponse`
Expand Down
250 changes: 250 additions & 0 deletions examples/transfer_from_opentx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@

This document is about how to use the transfer_from_opentx example to do open transaction operation.
All the addresses and keys are all in my development local node, you should not use in the production environment.
# Sighash open transaction example
1. Build an opentx address
```bash
./target/debug/examples/transfer_from_opentx build --receiver ckt1qyqt8xpk328d89zgl928nsgh3lelch33vvvq5u3024
```
The output:
```json
{
"lock-arg": "0x00b398368a8ed39448f95479c1178ff3fc5e31631810",
"lock-hash": "0x3f54ccaf46b3472b55eaa2e2c0a5cae87575b3de90a81fe60206dd5c0951ffa8",
"mainnet": "ckb1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqv8f7ak",
"testnet": "ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7"
}
```
2. Transfer capacity to the address
```bash
ckb-cli wallet transfer --from-account 0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7 \
--to-address ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 99 --skip-check-to-address
# 0x937deeb989bbd7f4bd0273bf2049d7614615dd58a32090b0093f23a692715871
```
3. Generate the transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx --sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 98.0 --open-capacity 1.0\
--tx-file tx.json
```
4. Sign the transaction
```bash
./target/debug/examples/transfer_from_opentx sign-open-tx --sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--tx-file tx.json
```
5. Add input, with capacity 98.99999588
```bash
./target/debug/examples/transfer_from_opentx add-input --tx-hash df85d2aaa44d50b1db286bdb2fbd8682cad12d6858b269d2531403ba5e63a2eb --index 0 --tx-file tx.json
```
6. Add output, capacity is 98.99999588(original) + 1(open capacity) - 0.001(fee)
```bash
./target/debug/examples/transfer_from_opentx add-output --to-address ckt1qyqy68e02pll7qd9m603pqkdr29vw396h6dq50reug --capacity 99.99899588 --tx-file tx.json
```
7. Sign the new input
```bash
./target/debug/examples/transfer_from_opentx sighash-sign-tx --sender-key 7068b4dc5289353c688e2e67b75207eb5574ba4938091cf5626a4d0f5cc91668 --tx-file tx.json
```
8. send the tx
```bash
./target/debug/examples/transfer_from_opentx send --tx-file tx.json
# 0xebb9d9ff39efbee5957d6f7d19a4a17f1ac2e69dbc9289e4931cef6b832f4d57
```

# Ethereum open transaction example
1. build an opentx address
```bash
./target/debug/examples/transfer_from_opentx build --ethereum-receiver 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d
```
output:
```json
{
"lock-arg": "0x01cf2485c76aff1f2b4464edf04a1c8045068cf7e010",
"lock-hash": "0x057dcd204f26621ef49346ed77d2bdbf3069b83a5ef0a2b52be5299a93507cf6",
"mainnet": "ckb1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgpeujgt3m2lu0jk3ryahcy58yqg5rgealqzqjzc5z5",
"testnet": "ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgpeujgt3m2lu0jk3ryahcy58yqg5rgealqzqf4vcru"
}
```
2. Transfer capacity to the address
```bash
ckb-cli wallet transfer --from-account 0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7 \
--to-address ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgpeujgt3m2lu0jk3ryahcy58yqg5rgealqzqf4vcru \
--capacity 99 --skip-check-to-address
# 0xbd696b87629dfe38136c52e579800a432622baf5893b61365c7a18902a9ccd60
```
3. Generate the transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx --ethereum-sender-key 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 98.0 --open-capacity 1.0\
--tx-file tx.json
```
4. Sign the transaction
```bash
./target/debug/examples/transfer_from_opentx sign-open-tx --sender-key 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d \
--tx-file tx.json
```
5. Add input, with capacity 99.99899588
```bash
./target/debug/examples/transfer_from_opentx add-input --tx-hash ebb9d9ff39efbee5957d6f7d19a4a17f1ac2e69dbc9289e4931cef6b832f4d57 --index 1 --tx-file tx.json
```
6. Add output, capacity is 99.99899588(original) + 1(open capacity) - 0.001(fee)
```bash
./target/debug/examples/transfer_from_opentx add-output --to-address ckt1qyqy68e02pll7qd9m603pqkdr29vw396h6dq50reug --capacity 100.99799588 --tx-file tx.json
```
7. Sighash sign the new input
```bash
./target/debug/examples/transfer_from_opentx sighash-sign-tx --sender-key 7068b4dc5289353c688e2e67b75207eb5574ba4938091cf5626a4d0f5cc91668 --tx-file tx.json
```
8. Send the transaction
```bash
./target/debug/examples/transfer_from_opentx send --tx-file tx.json
# 0x621077216f3bf7861beacd3cdda44f7a5854454fcd133922b89f0addd0330e6b
```
# Multisig open transaction example
1. build an opentx address
```bash
./target/debug/examples/transfer_from_opentx build --require-first-n 0 \
--threshold 2 \
--sighash-address ckt1qyqt8xpk328d89zgl928nsgh3lelch33vvvq5u3024 \
--sighash-address ckt1qyqvsv5240xeh85wvnau2eky8pwrhh4jr8ts8vyj37 \
--sighash-address ckt1qyqywrwdchjyqeysjegpzw38fvandtktdhrs0zaxl4
```
The output:
```json
{
"lock-arg": "0x065d7d0128eeaa6f9656a229b42aadd0b177d387eb10",
"lock-hash": "0xf5202949800af0b454b2e4806c57da1d0f3ae87f7b9f4b698d9f3b71162ec196",
"mainnet": "ckb1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgxt47sz28w4fhev44z9x6z4twsk9ma8pltzqmtamce",
"testnet": "ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgxt47sz28w4fhev44z9x6z4twsk9ma8pltzqqufhe3"
}
```
2. Transfer capacity to the address
```bash
ckb-cli wallet transfer --from-account 0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7 \
--to-address ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgxt47sz28w4fhev44z9x6z4twsk9ma8pltzqqufhe3 \
--capacity 99 --skip-check-to-address
# 0xf993b27a0129f72ec0a889cb016987c3cef00f7819461e51d5755464da6adf1b
```
3. Generate the transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx \
--require-first-n 0 \
--threshold 2 \
--sighash-address ckt1qyqt8xpk328d89zgl928nsgh3lelch33vvvq5u3024 \
--sighash-address ckt1qyqvsv5240xeh85wvnau2eky8pwrhh4jr8ts8vyj37 \
--sighash-address ckt1qyqywrwdchjyqeysjegpzw38fvandtktdhrs0zaxl4 \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 98.0 --open-capacity 1.0 \
--tx-file tx.json
```
4. Sign the transaction, this step can sign seperately with each sender-key
```bash
./target/debug/examples/transfer_from_opentx sign-open-tx \
--sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--sender-key d00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc \
--tx-file tx.json
```
5. Add input, with capacity 100.99799588
```bash
./target/debug/examples/transfer_from_opentx add-input --tx-hash 621077216f3bf7861beacd3cdda44f7a5854454fcd133922b89f0addd0330e6b --index 1 --tx-file tx.json
```
6. Add output, capacity is 100.99799588(original) + 1(open capacity) - 0.001(fee)
```bash
./target/debug/examples/transfer_from_opentx add-output --to-address ckt1qyqy68e02pll7qd9m603pqkdr29vw396h6dq50reug --capacity 101.99699588 --tx-file tx.json
```
7. Sighash sign the new input
```bash
./target/debug/examples/transfer_from_opentx sighash-sign-tx --sender-key 7068b4dc5289353c688e2e67b75207eb5574ba4938091cf5626a4d0f5cc91668 --tx-file tx.json
```
8. Send the tx
```bash
./target/debug/examples/transfer_from_opentx send --tx-file tx.json
# 0x577101b031d709992af99bd0715172bdb4d2eb7be9f11e84d6fb24ac3e1ac675
```
# Put multiple open transactions together
1. Build/sign sighash open transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx --sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 97 --open-capacity 1\
--tx-file tx-sighash.json
./target/debug/examples/transfer_from_opentx sign-open-tx --sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--tx-file tx-sighash.json
```
2. Build/sign sighash open transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx --ethereum-sender-key 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 97 --open-capacity 1\
--tx-file tx-ethereum.json
./target/debug/examples/transfer_from_opentx sign-open-tx --sender-key 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d \
--tx-file tx-ethereum.json
```
3. Build/sign multisig open transaction
```bash
./target/debug/examples/transfer_from_opentx gen-open-tx \
--require-first-n 0 \
--threshold 2 \
--sighash-address ckt1qyqt8xpk328d89zgl928nsgh3lelch33vvvq5u3024 \
--sighash-address ckt1qyqvsv5240xeh85wvnau2eky8pwrhh4jr8ts8vyj37 \
--sighash-address ckt1qyqywrwdchjyqeysjegpzw38fvandtktdhrs0zaxl4 \
--receiver ckt1qqwmhmsv9cmqhag4qxguaqux05rc4qlyq393vu45dhxrrycyutcl6qgqkwvrdz5w6w2y372508q30rlnl30rzccczqhsaju7 \
--capacity 97 --open-capacity 1.0 \
--tx-file tx-multisig.json
./target/debug/examples/transfer_from_opentx sign-open-tx \
--sender-key 8dadf1939b89919ca74b58fef41c0d4ec70cd6a7b093a0c8ca5b268f93b8181f \
--sender-key d00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc \
--tx-file tx-multisig.json
```
4. merge into one transaction

You can merge them in one command:
```bash
./target/debug/examples/transfer_from_opentx merge-open-tx \
--in-tx-file tx-sighash.json \
--in-tx-file tx-ethereum.json \
--in-tx-file tx-multisig.json \
--tx-file tx.json
```
The other way get the same merge result:
+ Merge first 2, then merge the last
```bash
./target/debug/examples/transfer_from_opentx merge-open-tx \
--in-tx-file tx-sighash.json \
--in-tx-file tx-ethereum.json \
--tx-file tx.json
./target/debug/examples/transfer_from_opentx merge-open-tx \
--in-tx-file tx.json \
--in-tx-file tx-multisig.json \
--tx-file tx.json
```
+ Merge last 2, then merge the first
```bash
./target/debug/examples/transfer_from_opentx merge-open-tx \
--in-tx-file tx-ethereum.json \
--in-tx-file tx-multisig.json \
--tx-file tx.json
./target/debug/examples/transfer_from_opentx merge-open-tx \
--in-tx-file tx-sighash.json \
--in-tx-file tx.json \
--tx-file tx.json
```
5. Add input, with capacity 101.99699588
```bash
./target/debug/examples/transfer_from_opentx add-input --tx-hash 577101b031d709992af99bd0715172bdb4d2eb7be9f11e84d6fb24ac3e1ac675 --index 1 --tx-file tx.json
```
6. Add output, capacity is 101.99699588(original) + 3(1 open capacity each) - 0.001(fee)
```bash
./target/debug/examples/transfer_from_opentx add-output --to-address ckt1qyqy68e02pll7qd9m603pqkdr29vw396h6dq50reug --capacity 104.99599588 --tx-file tx.json
```
7. Sighash sign the new input
```bash
./target/debug/examples/transfer_from_opentx sighash-sign-tx --sender-key 7068b4dc5289353c688e2e67b75207eb5574ba4938091cf5626a4d0f5cc91668 --tx-file tx.json
```
8. Send the transaction
```bash
./target/debug/examples/transfer_from_opentx send --tx-file tx.json
# 0x4fd5d4adfb009a6e342a9e8442ac54989e28ef887b1fec60c3703e4c4d223b39
```
Loading