-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7926ab7
commit 07592ad
Showing
29 changed files
with
271 additions
and
178 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Events | ||
|
||
```rs | ||
{{#include ./events.ts}} | ||
``` | ||
|
||
```ts | ||
Pallet name: balances, Event name: Withdraw | ||
Pallet name: balances, Event name: Transfer | ||
Pallet name: balances, Event name: Deposit | ||
Pallet name: balances, Event name: Deposit | ||
Pallet name: balances, Event name: Deposit | ||
Pallet name: transactionPayment, Event name: TransactionFeePaid | ||
Pallet name: system, Event name: ExtrinsicSuccess | ||
Transfer from: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY, to: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty, amount: 1000000000000000000 | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SDK, Events } from "./../../../../src/index" | ||
|
||
export async function run() { | ||
const sdk = await SDK.New(SDK.localEndpoint()) | ||
|
||
const account = SDK.alice() | ||
|
||
const dest = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" | ||
const value = SDK.oneAvail() | ||
const tx = sdk.tx.balances.transferKeepAlive(dest, value) | ||
const res = (await tx.executeWaitForInclusion(account))._unsafeUnwrap() | ||
|
||
for (const eventRecord of res.events) { | ||
console.log(`Pallet name: ${eventRecord.event.section}, Event name: ${eventRecord.event.method}`) | ||
} | ||
|
||
// findFirstEvent, findLastEvent, findEvent | ||
const event = res.findFirstEvent(Events.Balances.Transfer) | ||
if (event == null) throw Error("qed") | ||
|
||
console.log(`Transfer from: ${event.from}, to: ${event.to}, amount: ${event.amount}`) | ||
} |
This file contains 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,6 +1,9 @@ | ||
import * as Batch from "./batch" | ||
import * as DA from "./data_submission" | ||
import * as Events from "./events" | ||
import * as Transactions from "./transactions" | ||
import * as Validator from "./validator" | ||
|
||
export async function run() { | ||
await DA.run() | ||
await Validator.run() | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Transactions | ||
|
||
```rs | ||
{{#include ./transactions.ts}} | ||
``` | ||
|
||
```ts | ||
Tx Pallet name: timestamp, Tx Name: set, Tx Hash: 0xe5e3356b11db7a8528f58c302d678bcc77535cfd3af6e6996caeaffad2dd81cd | ||
Event Pallet name: system, Event Name: ExtrinsicSuccess | ||
Tx Pallet name: balances, Tx Name: transferKeepAlive, Tx Hash: 0x0338202e3f858c292930630151ee6360b52ce393726b1d5fed50f9c597934d76 | ||
Event Pallet name: balances, Event Name: Withdraw | ||
Event Pallet name: balances, Event Name: Transfer | ||
Event Pallet name: balances, Event Name: Deposit | ||
Event Pallet name: balances, Event Name: Deposit | ||
Event Pallet name: balances, Event Name: Deposit | ||
Event Pallet name: transactionPayment, Event Name: TransactionFeePaid | ||
Event Pallet name: system, Event Name: ExtrinsicSuccess | ||
Transfer dest: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty, value: 1000000000000000000 | ||
Tx Pallet name: vector, Tx Name: failedSendMessageTxs, Tx Hash: 0x92cdb77314063a01930b093516d19a453399710cc8ae635ff5ab6cf76b26f218 | ||
Event Pallet name: system, Event Name: ExtrinsicSuccess | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { SDK, Block, Events, CallData } from "./../../../../src/index" | ||
|
||
export async function run() { | ||
const sdk = await SDK.New(SDK.localEndpoint()) | ||
const api = sdk.api | ||
|
||
const account = SDK.alice() | ||
|
||
const dest = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" | ||
const value = SDK.oneAvail() | ||
const tx = sdk.tx.balances.transferKeepAlive(dest, value) | ||
const res = (await tx.executeWaitForInclusion(account))._unsafeUnwrap() | ||
|
||
const block = await Block.New(api, res.blockHash) | ||
|
||
// transactionAll, transactionBySigner, transactionByIndex, transactionByHash, transactionByAppId | ||
for (const [index, tx] of block.transactionAll().entries()) { | ||
console.log(`Tx Pallet name: ${tx.method.section}, Tx Name: ${tx.method.method}, Tx Hash: ${tx.hash.toHex()}`) | ||
|
||
const eventRecords = await Events.fetchEvents(api, res.blockHash, index) | ||
for (const eventRecord of eventRecords) { | ||
console.log(`\tEvent Pallet name: ${eventRecord.event.section}, Event Name: ${eventRecord.event.method}`) | ||
} | ||
const balance_tx = CallData.Balances.TransferKeepAlive.decode(tx) | ||
if (balance_tx != null) { | ||
console.log(`Transfer dest: ${balance_tx.dest}, value: ${balance_tx.value}`) | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Validator | ||
|
||
```rs | ||
{{#include ./validator.ts}} | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SDK, BN, utils } from "./../../../../src/index" | ||
|
||
export async function run() { | ||
const sdk = await SDK.New(SDK.localEndpoint()) | ||
const api = sdk.api | ||
|
||
const account = SDK.alice() | ||
|
||
// Bond minValidatorBond or 1 AVAIL token | ||
const minValidatorBond: BN = ((await api.query.staking.minValidatorBond()) as any) || SDK.oneAvail() | ||
|
||
// Bond | ||
const bondTx = sdk.tx.staking.bond(minValidatorBond, "Staked") | ||
const _r1 = (await bondTx.executeWaitForInclusion(account))._unsafeUnwrap() | ||
|
||
// Generate Session Keys | ||
const keysBytes = await api.rpc.author.rotateKeys() | ||
const keys = utils.deconstruct_session_keys(keysBytes.toString()) | ||
|
||
// Set Keys | ||
const setKeysTx = sdk.tx.session.setKeys(keys) | ||
const _r2 = (await setKeysTx.executeWaitForInclusion(account))._unsafeUnwrap() | ||
|
||
// Validate | ||
const validateTx = sdk.tx.staking.validate(50, false) | ||
const _r3 = (await validateTx.executeWaitForInclusion(account))._unsafeUnwrap() | ||
} |
Oops, something went wrong.