Skip to content

Commit

Permalink
Added doc extrinsic examples for as_multi and approving_as_multi
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Oct 17, 2024
1 parent 1d7d426 commit f3d456d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 5 deletions.
42 changes: 42 additions & 0 deletions avail-js/docs/extrinsics/multisig_approving_as_multi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SDK, WaitFor, Keyring } from "./../../src/index"

const main = async () => {
const providerEndpoint = "ws://127.0.0.1:9944"
const sdk = await SDK.New(providerEndpoint)

// Multisig Signatures
const alice = new Keyring({ type: "sr25519" }).addFromUri("//Alice")
const bobAddress = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"

// Create Multisig Account
const threshold = 2
const multisigAddress = sdk.util.generateMultisig([alice.address, bobAddress], threshold)

// Define what action will be taken by the multisig account
const amount = SDK.oneAvail()
const call = sdk.api.tx.balances.transferKeepAlive(multisigAddress, amount)
// Data needed for multisig approval and execution
const callHash = call.method.hash.toString()
const maxWeight = (await call.paymentInfo(alice.address)).weight

// Create New Multisig
console.log("Alice is creating a Multisig Transaction...")
const call1signatures = sdk.util.sortMultisigAddresses([bobAddress])
const result = await sdk.tx.multisig.approveAsMulti(
threshold,
call1signatures,
null,
callHash,
maxWeight,
WaitFor.BlockInclusion,
alice,
)
if (result.isErr()) {
console.log(result.error)
process.exit(1)
}

console.log(JSON.stringify(result.value, null, 2))
process.exit()
}
main()
43 changes: 43 additions & 0 deletions avail-js/docs/extrinsics/multisig_as_multi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SDK, WaitFor, Keyring, MultisigTimepoint } from "./../../src/index"

const main = async () => {
const providerEndpoint = "ws://127.0.0.1:9944"
const sdk = await SDK.New(providerEndpoint)

// Multisig Signatures
const bob = new Keyring({ type: "sr25519" }).addFromUri("//Bob")
const aliceAddress = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"

// Create Multisig Account
const threshold = 2
const multisigAddress = sdk.util.generateMultisig([aliceAddress, bob.address], threshold)

// Define what action will be taken by the multisig account
const amount = SDK.oneAvail()
const call = sdk.api.tx.balances.transferKeepAlive(multisigAddress, amount)
// Data needed for multisig approval and execution
const callData = call.unwrap().toHex()
const maxWeight = (await call.paymentInfo(aliceAddress)).weight
const timepoint: MultisigTimepoint = { height: 4, index: 1 }

// Approving and executing Multisig transaction
console.log("Bob is approving and executing the existing Multisig Transaction...")
const call2signatures = sdk.util.sortMultisigAddresses([aliceAddress])
const secondResult = await sdk.tx.multisig.asMulti(
threshold,
call2signatures,
timepoint,
callData,
maxWeight,
WaitFor.BlockInclusion,
bob,
)
if (secondResult.isErr()) {
console.log(secondResult.error)
process.exit(1)
}

console.log(JSON.stringify(secondResult.value, null, 2))
process.exit()
}
main()
1 change: 0 additions & 1 deletion avail-js/src/sdk/transactions/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ISubmittableResult } from "@polkadot/types/types/extrinsic"
import { EventRecord, Weight } from "@polkadot/types/interfaces/types"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result, ok } from "neverthrow"
import { SignerOptions } from "@polkadot/api/types"
import { WaitFor, standardCallback, TransactionFailed, TransactionOptions } from "./common"
import { MultisigTimepoint, parseTransactionResult, TxResultDetails } from "../utils"

Expand Down
1 change: 0 additions & 1 deletion avail-js/src/sdk/transactions/nomination_pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { BN } from "@polkadot/util"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result, ok } from "neverthrow"

import { SignerOptions } from "@polkadot/api/types"
import { WaitFor, standardCallback, TransactionFailed, TransactionOptions } from "./common"
import { commissionNumberToPerbill, parseTransactionResult, TxResultDetails } from "../utils"

Expand Down
1 change: 0 additions & 1 deletion avail-js/src/sdk/transactions/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result, ok } from "neverthrow"

import * as TransactionData from "./../transaction_data"
import { SignerOptions } from "@polkadot/api/types"
import { WaitFor, standardCallback, TransactionFailed, TransactionOptions } from "./common"
import { commissionNumberToPerbill, parseTransactionResult, TxResultDetails } from "../utils"

Expand Down
4 changes: 2 additions & 2 deletions avail-js/src/sdk/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApiPromise } from "@polkadot/api"
import { err, ok, Result } from "neverthrow"
import { ISubmittableResult } from "@polkadot/types/types/extrinsic"
import { EventRecord, H256, Weight } from "@polkadot/types/interfaces"
import { EventRecord, H256 } from "@polkadot/types/interfaces"
import { decodeError } from "../../helpers"
import { getBlockHashAndTxHash, standardCallback, WaitFor } from "../transactions/common"
import { getBlockHashAndTxHash, WaitFor } from "../transactions/common"
import { createKeyMulti, encodeAddress, sortAddresses } from "@polkadot/util-crypto"

export class TxResultDetails {
Expand Down

0 comments on commit f3d456d

Please sign in to comment.