Skip to content
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

Feat: Transaction service refactoring #1053

Merged
merged 21 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/renderer/entities/multisig/lib/multisigTx/common/utils.ts
tuul-wq marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ import {
MultisigEvent,
MultisigTransaction,
MultisigTxInitStatus,
Transaction,
TransactionType,
} from '@renderer/entities/transaction/model/transaction';
import { PendingMultisigTransaction } from './types';
import { getCreatedDate } from '@renderer/shared/lib/utils';
import { getCreatedDate, toAccountId } from '@renderer/shared/lib/utils';
import { ExtrinsicResultParams } from '@renderer/entities/transaction';

type MultisigTxResult = {
transaction: MultisigTransaction;
event: MultisigEvent;
};

export const getPendingMultisigTxs = async (
api: ApiPromise,
Expand Down Expand Up @@ -142,3 +150,48 @@ export const createTransactionPayload = (
accountId: account.accountId || '0x',
};
};

export const buildMultisigTx = (
tx: Transaction,
multisigTx: Transaction,
params: ExtrinsicResultParams,
account: MultisigAccount,
description?: string,
): MultisigTxResult | undefined => {
if (tx.type !== TransactionType.MULTISIG_AS_MULTI) return;
return;
}
egor0798 marked this conversation as resolved.
Show resolved Hide resolved

const transaction: MultisigTransaction = {
accountId: account.accountId,
chainId: multisigTx.chainId,
signatories: account.signatories,
callData: multisigTx.args.callData,
callHash: multisigTx.args.callHash,
transaction: tx,
status: MultisigTxInitStatus.SIGNING,
blockCreated: params.timepoint.height,
indexCreated: params.timepoint.index,
description,
dateCreated: Date.now(),
};

const event: MultisigEvent = {
txAccountId: transaction.accountId,
txChainId: transaction.chainId,
txCallHash: transaction.callHash,
txBlock: transaction.blockCreated,
txIndex: transaction.indexCreated,
status: 'SIGNED',
accountId: toAccountId(multisigTx.address),
extrinsicHash: params.extrinsicHash,
eventBlock: params.timepoint.height,
eventIndex: params.timepoint.index,
dateCreated: Date.now(),
};

return {
event,
transaction,
};
};
39 changes: 36 additions & 3 deletions src/renderer/entities/transaction/lib/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ApiPromise } from '@polkadot/api';
import { UnsignedTransaction } from '@substrate/txwrapper-polkadot';
import { BaseTxInfo, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-polkadot';
import { Weight } from '@polkadot/types/interfaces';
import { SubmittableExtrinsic } from '@polkadot/api/types';

import { Address, CallData, HexString, Timepoint, Threshold, AccountId } from '@renderer/domain/shared-kernel';
import { DecodedTransaction, Transaction } from '@renderer/entities/transaction/model/transaction';
import { Address, CallData, HexString, Timepoint, Threshold, AccountId, ChainId } from '@renderer/domain/shared-kernel';
import { DecodedTransaction, Transaction, TransactionType } from '@renderer/entities/transaction/model/transaction';
import { TxWrappers } from '@renderer/entities/transaction';
import { MultisigAccount } from '@renderer/entities/account';

// =====================================================
// =========== ITransactionService interface ===========
Expand All @@ -31,6 +33,37 @@ export type ITransactionService = {
getTransactionHash: (transaction: Transaction, api: ApiPromise) => HashData;
decodeCallData: (api: ApiPromise, accountId: Address, callData: CallData) => DecodedTransaction;
verifySignature: (payload: Uint8Array, signature: HexString, accountId: AccountId) => Boolean;
setTxs: (txs: Transaction[]) => void;
txs: Transaction[];
setWrappers: (wrappers: TxWrappers[]) => void;
wrapTx: (tx: Transaction, api: ApiPromise, addressPrefix: number) => Transaction;
buildTransaction: (
type: TransactionType,
address: Address,
chainId: ChainId,
args: Record<string, any>,
) => Transaction;
};

// =====================================================
// =========== IExtrinsicService interface ===========
// =====================================================
export type IExtrinsicService = {
getUnsignedTransaction: Record<
TransactionType,
(args: Transaction, info: BaseTxInfo, options: OptionsWithMeta, api: ApiPromise) => UnsignedTransaction
>;
getExtrinsic: Record<
TransactionType,
(args: Record<string, any>, api: ApiPromise) => SubmittableExtrinsic<'promise'>
>;
wrapAsMulti: (
account: MultisigAccount,
signerAccountId: AccountId,
transaction: Transaction,
api: ApiPromise,
addressPrefix: number,
) => Transaction;
};

// =====================================================
Expand Down
Loading
Loading