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 14 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
50 changes: 49 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,16 @@ import {
MultisigEvent,
MultisigTransaction,
MultisigTxInitStatus,
Transaction,
} 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 +149,44 @@ export const createTransactionPayload = (
accountId: account.accountId || '0x',
};
};

export const buildMultisigTx = (
tx: Transaction,
multisigTx: Transaction,
params: ExtrinsicResultParams,
account: MultisigAccount,
description?: string,
): MultisigTxResult => {
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,
};
};
15 changes: 13 additions & 2 deletions src/renderer/entities/transaction/lib/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { 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';

// =====================================================
// =========== ITransactionService interface ===========
Expand All @@ -31,6 +32,16 @@ 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;
};

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