Skip to content

Commit

Permalink
fix(sdk-coin-dot): make controller optional for bond call
Browse files Browse the repository at this point in the history
  • Loading branch information
noel-bitgo committed Aug 14, 2023
1 parent 902558a commit a6f6a0d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion modules/sdk-coin-dot/src/lib/batchTransactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export class BatchTransactionBuilder extends TransactionBuilder {
const baseTxInfo = this.createBaseTxInfo();
const unsigned = methods.staking.bond(
{
controller: args.controller.id,
// TODO(EA-1242): update DOT library to remove controller optional field -> https://github.com/paritytech/txwrapper-core/pull/309 and https://github.com/paritytech/substrate/pull/14039
controller: args.controller?.id || '',
value: args.value,
payee: this.getPayee(args.payee),
},
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export type StakeArgsPayeeRaw = { controller?: null; stash?: null; staked?: null
*/
export interface StakeArgs {
value: string;
controller: { id: string };
controller?: { id: string };
payee: StakeArgsPayee;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export type StakeBatchCallPayee =

export interface StakeBatchCallArgs {
value: string;
controller: { id: string };
controller?: { id: string };
payee: StakeBatchCallPayee;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/lib/stakingBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class StakingBuilder extends TransactionBuilder {
if (decodedTxn.method?.name === MethodNames.Bond) {
const txMethod = decodedTxn.method.args as unknown as StakeArgs;
const value = txMethod.value;
const controller = txMethod.controller.id;
const controller = txMethod.controller?.id;
const payee = txMethod.payee;
const validationResult = StakeTransactionSchema.validate({ value, controller, payee });
if (validationResult.error) {
Expand All @@ -150,7 +150,7 @@ export class StakingBuilder extends TransactionBuilder {
console.log('[Dot staking debug] calling owner: ', JSON.stringify(txMethod));
this.owner({
address: utils.decodeDotAddress(
txMethod.controller.id,
txMethod.controller?.id || '',
utils.getAddressFormat(this._coinConfig.name as DotAssetTypes)
),
});
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-dot/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ export class Transaction extends BaseTransaction {
const txMethod = decodedTx.method.args;
if (utils.isBond(txMethod)) {
const keypair = new KeyPair({
pub: Buffer.from(decodeAddress(txMethod.controller.id, false, this._registry.chainSS58)).toString('hex'),
pub: Buffer.from(decodeAddress(txMethod.controller?.id || '', false, this._registry.chainSS58)).toString(
'hex'
),
});

result.controller = keypair.getAddress(utils.getAddressFormat(this._coinConfig.name as DotAssetTypes));
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/src/lib/txnSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const TransferAllTransactionSchema = joi.object({

const CreateStakeTransactionSchema = joi.object({
value: joi.string().required(),
controller: addressSchema.required(),
controller: joi.string().optional(),
payee: [
joi.string(),
joi.object({
Expand Down

0 comments on commit a6f6a0d

Please sign in to comment.