-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
940a7eb
Draft
ChrisChinchilla fb062a6
Draft
ChrisChinchilla 7c73f85
Draft
ChrisChinchilla 37b8ab0
Draft
ChrisChinchilla e2cfded
Update sdk/02_tutorial/01_welcome.md
ChrisChinchilla ebb2d9a
Update sdk/02_tutorial/03_overview.md
ChrisChinchilla 8bafdae
Update sdk/02_tutorial/06_holder/02_create_presentation.md
ChrisChinchilla 7ad3d45
Update sdk/02_tutorial/07_verification.md
ChrisChinchilla 54bac00
Update sdk/02_tutorial/05_issuer/index.md
ChrisChinchilla 7c939a6
Update sdk/02_tutorial/05_issuer/03_issue_credential.md
ChrisChinchilla 3195f50
Update sdk/02_tutorial/06_holder/02_create_presentation.md
ChrisChinchilla 6101763
Update sdk/02_tutorial/06_holder/02_create_presentation.md
ChrisChinchilla ef4695e
Changes from review
ChrisChinchilla 19b02d5
Merge branch '3594-update-workshop' of github.com:KILTprotocol/docs i…
ChrisChinchilla 58dbf0e
Changes from review
ChrisChinchilla c4874d8
Update sdk/02_tutorial/05_issuer/03_issue_credential.md
ChrisChinchilla fa9dfe2
Update sdk/02_tutorial/06_holder/02_create_presentation.md
ChrisChinchilla a827c65
Update sdk/02_tutorial/07_verification.md
ChrisChinchilla 020ebe8
Update sdk/02_tutorial/07_verification.md
ChrisChinchilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
12 changes: 0 additions & 12 deletions
12
code_examples/sdk_examples/src/workshop/holder/createClaim.ts
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
code_examples/sdk_examples/src/workshop/holder/createPresentation.ts
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
code_examples/sdk_examples/src/workshop/holder/generateAccount.ts
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
code_examples/sdk_examples/src/workshop/holder/generateCredential.ts
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
code_examples/sdk_examples/src/workshop/holder/generateKeypairs.ts
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
code_examples/sdk_examples/src/workshop/holder/generateLightDid.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.