1- # NBV Storage
1+ # Bitcoin Vaults
22A storage module for Native Bitcoin Vaults on substrate.
33
4- - [ NBV Storage ] ( #bitcoin-vaults )
4+ - [ Bitcoin Vaults ] ( #bitcoin-vaults )
55 - [ Overview] ( #overview )
66 - [ Terminology] ( #terminology )
77 - [ Interface] ( #interface )
@@ -10,6 +10,7 @@ A storage module for Native Bitcoin Vaults on substrate.
1010 - [ Getters] ( #getters )
1111 - [ Usage] ( #usage )
1212 - [ Polkadot-js CLI] ( #polkadot-js-cli )
13+ - [ Enabling Offchain Worker] ( #enabling-offchain-worker )
1314 - [ Insert an xpub] ( #insert-an-xpub )
1415 - [ Query a specific stored xpub] ( #query-a-specific-stored-xpub )
1516 - [ Query accounts hash that links to the xpub] ( #query-accounts-hash-that-links-to-the-xpub )
@@ -26,6 +27,7 @@ A storage module for Native Bitcoin Vaults on substrate.
2627 - [ Finalize (and posibly broadcast) a PSBT] ( #finalize-and-posibly-broadcast-a-psbt )
2728 - [ Broadcast a PSBT] ( #broadcast-a-psbt )
2829 - [ Polkadot-js api (javascript library)] ( #polkadot-js-api-javascript-library )
30+ - [ Enabling Offchain Worker] ( #enabling-offchain-worker-1 )
2931 - [ Insert an xpub] ( #insert-an-xpub-1 )
3032 - [ Query stored xpubs] ( #query-stored-xpubs )
3133 - [ Query accounts hash that links to the xpub] ( #query-accounts-hash-that-links-to-the-xpub-1 )
@@ -109,106 +111,120 @@ The following examples will be using the following credentials and testing data:
109111
110112### Polkadot-js CLI
111113
114+ #### Enabling Offchain Worker
115+ In order to enable vault-related features, an account needs to be linked to the offchain worker. This process needs to be done just once, preferably by one of the chain administrators:
116+
117+ ``` bash
118+ # key type (constant to bdks), suri, public key in hex
119+ polkadot-js-api rpc.author.insertKey ' bdks' ' //Alice' ' 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'
120+ ```
121+
112122#### Insert an xpub
113123Note that the identity data structure is identical to the original setIdentity extrinsic from the identity pallet and additional fields can be specified.
114- The xpub to store is sent on the second parameter and the pallet will handle the link between xpub and hash.
124+ The xpub to store is sent on the second parameter and the pallet will handle the link between xpub and hash.
115125``` bash
116- polkadot-js-api tx.nbvStorage .setXpub " Zpub74kbYv5LXvBaJRcbSiihEEwuDiBSDztjtpSVmt6C6nB3ntbcEy4pLP3cJGVWsKbYKaAynfCwXnkuVncPGQ9Y4XwWJDWrDMUwTztdxBe7GcM" --seed " //Alice"
126+ polkadot-js-api tx.bitcoinVaults .setXpub " Zpub74kbYv5LXvBaJRcbSiihEEwuDiBSDztjtpSVmt6C6nB3ntbcEy4pLP3cJGVWsKbYKaAynfCwXnkuVncPGQ9Y4XwWJDWrDMUwTztdxBe7GcM" --seed " //Alice"
117127
118128```
119129
120130#### Query a specific stored xpub
121131If successful, the previous extrinsic returns a ` XPubStored ` event, which will contain the hash that links the identity and the xpub itself.
122132``` bash
123133# Note that the "0x9ee..." hash was returned from the previous tx.
124- polkadot-js-api query.nbvStorage .xpubs " 0x9ee1b23c479e03288d3d1d791abc580439598f70e7607c1de108c4bb6a9b5b6f"
134+ polkadot-js-api query.bitcoinVaults .xpubs " 0x9ee1b23c479e03288d3d1d791abc580439598f70e7607c1de108c4bb6a9b5b6f"
125135```
126136
127137#### Query accounts hash that links to the xpub
128138The hash can also be retrieved by specifying the owner account.
129139``` bash
130140# This tx should return the previous hash "0x9ee..."
131- polkadot-js-api query.nbvStorage .xpubsByOwner " 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
141+ polkadot-js-api query.bitcoinVaults .xpubsByOwner " 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
132142```
133143
134144#### Remove user's xpub
135145The account's xpub can be removed by submiting this extrinsic.
136146``` bash
137- polkadot-js-api tx.nbvStorage .removeXpub --seed " //Alice"
147+ polkadot-js-api tx.bitcoinVaults .removeXpub --seed " //Alice"
138148```
139149
140150#### Insert Vault
141151In order to create a vault, refer to the following extrinsic structure:
142152``` bash
143153# All users need to have an xpub
144- polkadot-js-api tx.nbvStorage .createVault 1 " description" true ' ["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"]' --seed " //Alice"
154+ polkadot-js-api tx.bitcoinVaults .createVault 1 " description" true ' ["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"]' --seed " //Alice"
145155```
146156
147157#### Query user's vaults (id)
148158
149159``` bash
150- polkadot-js-api query.nbvStorage .vaultsBySigner 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
160+ polkadot-js-api query.bitcoinVaults .vaultsBySigner 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
151161```
152162
153163#### Query vault details
154164
155165``` bash
156- polkadot-js-api query.nbvStorage .vaults 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf
166+ polkadot-js-api query.bitcoinVaults .vaults 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf
157167```
158168
159169#### Remove Vault
160170Only the vault's owner can remove it, a ` vault_id ` needs to be provided. This will remove all the vault proposals:
161171``` bash
162- polkadot-js-api tx.nbvStorage .removeVault " 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf" --seed " //Alice"
172+ polkadot-js-api tx.bitcoinVaults .removeVault " 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf" --seed " //Alice"
163173```
164174#### Propose
165175``` bash
166176# Parameters in order: vault_id, recipient address, amount in satoshis, and description:
167- polkadot-js-api tx.nbvStorage .propose 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf Zpub75bKLk9fCjgfELzLr2XS5TEcCXXGrci4EDwAcppFNBDwpNy53JhJS8cbRjdv39noPDKSfzK7EPC1Ciyfb7jRwY7DmiuYJ6WDr2nEL6yTkHi 1000 " lorem ipsum" --seed " //Alice"
177+ polkadot-js-api tx.bitcoinVaults .propose 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf Zpub75bKLk9fCjgfELzLr2XS5TEcCXXGrci4EDwAcppFNBDwpNy53JhJS8cbRjdv39noPDKSfzK7EPC1Ciyfb7jRwY7DmiuYJ6WDr2nEL6yTkHi 1000 " lorem ipsum" --seed " //Alice"
168178```
169179
170180#### Query vault's proposals
171181``` bash
172- polkadot-js-api query.nbvStorage .proposalsByVault 0x739829829f1a2891918f626a79bd830c0e46609f6db013a4f557746c014c374e
182+ polkadot-js-api query.bitcoinVaults .proposalsByVault 0x739829829f1a2891918f626a79bd830c0e46609f6db013a4f557746c014c374e
173183```
174184
175185#### Query proposals details
176186``` bash
177- polkadot-js-api query.nbvStorage .proposals 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675
187+ polkadot-js-api query.bitcoinVaults .proposals 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675
178188```
179189
180190#### Remove a proposal
181191``` bash
182- polkadot-js-api tx.nbvStorage .removeProposal 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 --seed " //Alice"
192+ polkadot-js-api tx.bitcoinVaults .removeProposal 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 --seed " //Alice"
183193```
184194
185195#### Sign a proposal
186196``` bash
187- polkadot-js-api tx.nbvStorage .savePsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 " <generated_psbt>" --seed " //Alice"
197+ polkadot-js-api tx.bitcoinVaults .savePsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 " <generated_psbt>" --seed " //Alice"
188198```
189199
190200#### Finalize (and posibly broadcast) a PSBT
191201The second parameter is a boolean flag, if set to true, the transaction will be automatically broadcasted.
192202``` bash
193- polkadot-js-api tx.nbvStorage .finalizePsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 < true/false> --seed " //Alice"
203+ polkadot-js-api tx.bitcoinVaults .finalizePsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 < true/false> --seed " //Alice"
194204```
195205
196206#### Broadcast a PSBT
197207This extrinsic is needed in case the PSBT is finalized but not broadcasted.
198208
199209``` bash
200- polkadot-js-api tx.nbvStorage .broadcastPsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 --seed " //Alice"
210+ polkadot-js-api tx.bitcoinVaults .broadcastPsbt 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675 --seed " //Alice"
201211```
202212
203213### Polkadot-js api (javascript library)
204- While most of the data flow is almost identical to its CLI counter part, the javascript library is much more versatile regarding queries. The API setup will be ommited .
214+ While most of the data flow is almost identical to its CLI counter part, the javascript library is much more versatile regarding queries. The API setup will be omitted .
205215
216+ #### Enabling Offchain Worker
217+ In order to enable vault-related features, an account needs to be linked to the offchain worker. This process needs to be done just once, preferably by one of the chain administrators:
206218
207- #### Insert an xpub
219+ ``` js
220+ # key type (constant to bdks), suri, public key in hex (no method was found for parsing an address to hex)
221+ const setKey = api .rpc .author .insertKey (" bdks" , " //Alice" , " 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" )
222+ ```
208223
224+ #### Insert an xpub
209225
210226``` js
211- const setXpub = api .tx .nbvStorage .setXpub (
227+ const setXpub = api .tx .bitcoinVaults .setXpub (
212228 " Zpub75bKLk9fCjgfELzLr2XS5TEcCXXGrci4EDwAcppFNBDwpNy53JhJS8cbRjdv39noPDKSfzK7EPC1Ciyfb7jRwY7DmiuYJ6WDr2nEL6yTkHi" );
213229const identityResult = await setCompleteIdentity .signAndSend (alice);
214230console .log (' Extrinsic sent with hash' , identityResult .toHex ());
@@ -217,13 +233,13 @@ console.log('Extrinsic sent with hash', identityResult.toHex());
217233
218234Query an xpub with specific hash;
219235``` js
220- const specificXpub = await api .query .nbvStorage .xpubs (" 0x9ee1b23c479e03288d3d1d791abc580439598f70e7607c1de108c4bb6a9b5b6f" );
236+ const specificXpub = await api .query .bitcoinVaults .xpubs (" 0x9ee1b23c479e03288d3d1d791abc580439598f70e7607c1de108c4bb6a9b5b6f" );
221237console .log (specificXpub .toHuman ());
222238```
223239
224240Query and print all the stored xpubs:
225241``` js
226- const xpubs = await api .query .nbvStorage .xpubs .entries ();
242+ const xpubs = await api .query .bitcoinVaults .xpubs .entries ();
227243xpubs .forEach (([key , value ]) => {
228244console .log (
229245 " Xpub hash:" ,
@@ -237,13 +253,13 @@ console.log(" Xpub value:", value.toHuman());
237253
238254Query an accounts hashed xpub.
239255``` js
240- const xpubsByOwner = await api .query .nbvStorage .xpubsByOwner (alice .address );
256+ const xpubsByOwner = await api .query .bitcoinVaults .xpubsByOwner (alice .address );
241257console .log (xpubsByOwner .toHuman () );
242258```
243259
244260Query and print all the xpub hashes, classified by account
245261``` js
246- const allXpubsByOwner = await api .query .nbvStorage .xpubsByOwner .entries ();
262+ const allXpubsByOwner = await api .query .bitcoinVaults .xpubsByOwner .entries ();
247263allXpubsByOwner .forEach (([key , value ]) => {
248264 console .log (
249265 " Account:" ,
@@ -256,79 +272,79 @@ allXpubsByOwner.forEach(([key, value]) => {
256272#### Remove user's xpub
257273
258274``` js
259- const removeAccountXpub = await api .tx .nbvStorage .removeXpub ().signAndSend (alice);
275+ const removeAccountXpub = await api .tx .bitcoinVaults .removeXpub ().signAndSend (alice);
260276console .log (' Tx sent with hash' , removeAccountXpub .toHex ());
261277```
262278
263279#### Insert Vault
264280``` js
265- const insertVault = await api .tx .nbvStorage .createVault (1 , " descripcion" , [" 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" ]).signAndSend (alice);
281+ const insertVault = await api .tx .bitcoinVaults .createVault (1 , " descripcion" , [" 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" ]).signAndSend (alice);
266282console .log (' Tx sent with hash' , insertVault .toHuman ());
267283```
268284
269285#### Query vaults ids by signer
270286
271287``` js
272- const vaultsBySigner = await api .query .nbvStorage .vaultsBySigner (alice .address );
288+ const vaultsBySigner = await api .query .bitcoinVaults .vaultsBySigner (alice .address );
273289console .log (vaultsBySigner .toHuman ());
274290```
275291
276292#### Query vaults details by id
277293
278294``` js
279- const vaultDetails = await api .query .nbvStorage .vaults (" 0x39c7ffa1b10d9d75fe20eb55e07788c23c06238b6e25e719a8e58d0bdf6bcd21" );
295+ const vaultDetails = await api .query .bitcoinVaults .vaults (" 0x39c7ffa1b10d9d75fe20eb55e07788c23c06238b6e25e719a8e58d0bdf6bcd21" );
280296console .log (vaultDetails .toHuman ());
281297```
282298
283299#### Remove vault
284300
285301``` js
286- const removeVault = await api .tx .nbvStorage .removeVault (" 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf" ).signAndSend (alice);
302+ const removeVault = await api .tx .bitcoinVaults .removeVault (" 0xdc08dcf7b4e6525bdd894433ffe45644262079dec2cdd8d5293e6b78c10edbcf" ).signAndSend (alice);
287303console .log (' Tx sent with hash' , removeVault .toHex ());
288304```
289305
290306#### Propose
291307``` js
292308// Parameters in order: vault_id, recipient address, amount in satoshis, and description:
293- const propose = await api .tx .nbvStorage
309+ const propose = await api .tx .bitcoinVaults
294310 .propose (" 0x739829829f1a2891918f626a79bd830c0e46609f6db013a4f557746c014c374e" , " Zpub75bKLk9fCjgfELzLr2XS5TEcCXXGrci4EDwAcppFNBDwpNy53JhJS8cbRjdv39noPDKSfzK7EPC1Ciyfb7jRwY7DmiuYJ6WDr2nEL6yTkHi" , 1000 , " lorem ipsum" ).signAndSend (alice);
295311console .log (' Tx sent with hash' , propose .toHuman ());
296312```
297313
298314#### Query vault's proposals
299315``` js
300- const vaultsProposals = await api .query .nbvStorage .proposalsByVault (" 0x739829829f1a2891918f626a79bd830c0e46609f6db013a4f557746c014c374e" );
316+ const vaultsProposals = await api .query .bitcoinVaults .proposalsByVault (" 0x739829829f1a2891918f626a79bd830c0e46609f6db013a4f557746c014c374e" );
301317console .log (vaultsProposals .toHuman () );
302318```
303319
304320#### Query proposals details
305321``` js
306- const proposal = await api .query .nbvStorage .proposals (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" );
322+ const proposal = await api .query .bitcoinVaults .proposals (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" );
307323console .log (proposal .toHuman ());
308324```
309325
310326#### Remove a proposal
311327``` js
312- const removeProposal = await api .tx .nbvStorage .removeProposal (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
328+ const removeProposal = await api .tx .bitcoinVaults .removeProposal (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
313329console .log (removeProposal .toHuman ());
314330```
315331
316332#### Sign a proposal
317333
318334``` js
319- const savePSBT = await api .tx .nbvStorage .savePsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
335+ const savePSBT = await api .tx .bitcoinVaults .savePsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
320336console .log (savePSBT .toHuman ());
321337```
322338
323339#### Finalize (and posibly broadcast) a PSBT
324340``` js
325- const finalizePsbt = await api .tx .nbvStorage .finalizePsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
341+ const finalizePsbt = await api .tx .bitcoinVaults .finalizePsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
326342console .log (finalizePsbt .toHuman ());
327343```
328344
329345#### Broadcast a PSBT
330346``` js
331- const broadcastPsbt = await api .tx .nbvStorage .broadcastPsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
347+ const broadcastPsbt = await api .tx .bitcoinVaults .broadcastPsbt (" 0x8426160f6705e480825a5bdccb2e465ad097d8a0a09981467348f884682d5675" ).signAndSend (alice);
332348console .log (broadcastPsbt .toHuman ());
333349```
334350
0 commit comments