Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 19
Update workshop to v1 of SDK#330
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
940a7ebfb062a67c73f8537b8ab0e2cfdedebb2d9a8bafdae7ad3d4554bac007c939a63195f506101763ef4695e19b02d558dbf0ec4874d8fa9dfe2a827c65020ebe8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,27 @@ | ||
| import * as Kilt from '@kiltprotocol/sdk-js' | ||
| import { BalanceUtils, Blockchain } from '@kiltprotocol/chain-helpers' | ||
| import type { | ||
| KiltAddress, | ||
| MultibaseKeyPair, | ||
| TransactionSigner | ||
| } from '@kiltprotocol/types' | ||
| import { Multikey } from '@kiltprotocol/utils' | ||
| import { BN } from '@polkadot/util' | ||
| import { setTimeout } from 'timers/promises' | ||
| async function failproofSubmit( | ||
| tx: Kilt.SubmittableExtrinsic, | ||
| submitter: Kilt.KeyringPair | ||
| ) { | ||
| try { | ||
| await Kilt.Blockchain.signAndSubmitTx(tx, submitter) | ||
| } catch { | ||
| // Try a second time after a small delay and fetching the right nonce. | ||
| const waitingTime = 12_000 // 12 seconds | ||
| console.log( | ||
| `First submission failed for workshop. Waiting ${waitingTime} ms before retrying.` | ||
| ) | ||
| await setTimeout(waitingTime) | ||
| console.log('Retrying...') | ||
| // nonce: -1 tells the client to fetch the latest nonce by also checking the tx pool. | ||
| const resignedBatchTx = await tx.signAsync(submitter, { nonce: -1 }) | ||
| await Kilt.Blockchain.submitSignedTx(resignedBatchTx) | ||
| } | ||
| } | ||
| // TODO: Look into tidier way with PD Keyring… | ||
| export async function getFunds( | ||
| faucetAccount: Kilt.KeyringPair, | ||
| recipient: Kilt.KiltAddress, | ||
| faucetAccount: MultibaseKeyPair, | ||
| recipient: MultibaseKeyPair, | ||
| kiltAmount: number | ||
| ) { | ||
| const api = Kilt.ConfigService.get('api') | ||
| const tx = api.tx.balances.transfer( | ||
| recipient, | ||
| Kilt.BalanceUtils.convertToTxUnit(new BN(kiltAmount), 0) | ||
| ) | ||
| await failproofSubmit(tx, faucetAccount) | ||
| console.log('Successfully transferred tokens') | ||
| } | ||
| const api = Kilt.ConfigService.get("api") | ||
| export async function endowAccounts( | ||
| faucetAccount: Kilt.KeyringPair, | ||
| destinationAccounts: Kilt.KiltAddress[], | ||
| amount: BN | ||
| ): Promise<void> { | ||
| const api = Kilt.ConfigService.get('api') | ||
| const transferBatch = destinationAccounts.map((acc) => | ||
| api.tx.balances.transfer( | ||
| acc, | ||
| Kilt.BalanceUtils.convertToTxUnit( | ||
| Kilt.BalanceUtils.KILT_COIN.mul(amount), | ||
| 0 | ||
| ) | ||
| ) | ||
| ) | ||
| console.log( | ||
| `Endowing test accounts "${destinationAccounts}" | ||
| from faucet "${faucetAccount.address}" | ||
| with ${Kilt.BalanceUtils.formatKiltBalance(amount, { | ||
| decimals: 0 | ||
| })} each...` | ||
| const tx = api.tx.balances.transferAllowDeath( | ||
| Multikey.decodeMultibaseKeypair(recipient).publicKey, | ||
| BalanceUtils.convertToTxUnit(new BN(kiltAmount), 0) | ||
| ) | ||
| const batchTx = api.tx.utility.batchAll(transferBatch) | ||
| await failproofSubmit(batchTx, faucetAccount) | ||
| console.log('Successfully transferred tokens') | ||
| const [faucetSigner] = await Kilt.getSignersForKeypair<KiltAddress>({ | ||
| keypair: faucetAccount | ||
| }) | ||
| await Blockchain.signAndSubmitTx(tx, <TransactionSigner>faucetSigner) | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.