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

Feature/mst account #925

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8cb3939
create_change_remove_mst
Kron1749 Oct 30, 2024
b1e060e
switch_between_mst_default
Kron1749 Oct 31, 2024
28294a5
logs_removed
Kron1749 Oct 31, 2024
7dfa42d
removed_comments_logs_some_updates
Kron1749 Oct 31, 2024
4ac260c
naming_updated
Kron1749 Oct 31, 2024
25fa1f4
moves_some_functions_to_mst_transfers
Kron1749 Nov 1, 2024
64e4cf9
removes_unnecessary_assertions
Kron1749 Nov 1, 2024
d65a90d
moved_functions_to_mst_index
Kron1749 Nov 5, 2024
fa88259
removed_comments_logs
Kron1749 Nov 5, 2024
c47a944
multisig_change_name_updated
Kron1749 Nov 5, 2024
d9bc4de
updated_with_getting_data_from_mst_account
Kron1749 Nov 5, 2024
7e3b710
made_update_with_override
Kron1749 Nov 5, 2024
5a8c2a5
updated_for_calldata_transfer_to_history_item
Kron1749 Nov 7, 2024
bbd67f5
updating_with_mst_flag_and_trxs
Kron1749 Nov 7, 2024
edcc8d1
updated_with_approve_from_mst
Kron1749 Nov 14, 2024
29e406d
updated_with_sign_from_cosigners_bugs_fixed
Kron1749 Nov 15, 2024
fa11141
version_updated
Kron1749 Nov 18, 2024
d055194
Merge branch 'master' into feature/mst-account
Kron1749 Nov 18, 2024
bf78f4a
some_updates_for_notifications
Kron1749 Nov 19, 2024
3a1ecc8
Merge branch 'feature/mst-account' of github.com:sora-xor/sora2-subst…
Kron1749 Nov 19, 2024
627b048
version_updated
Kron1749 Nov 19, 2024
adac1e7
updated_with_build
Kron1749 Nov 19, 2024
ba3f527
updated_with_deadline_and_fix_prevoius_acc
Kron1749 Nov 20, 2024
27a9130
Merge branch 'master' into feature/mst-account
Kron1749 Nov 20, 2024
099d8b0
fixed_deadline_trxs
Kron1749 Nov 20, 2024
d4927fd
removed_the_era_fix_other_signatures
Kron1749 Nov 20, 2024
f8cfdb1
Merge branch 'master' into feature/mst-account
stefashkaa Nov 20, 2024
f96d7cc
added_logs
Kron1749 Nov 21, 2024
0d05613
updated_with_builded_files
Kron1749 Nov 21, 2024
7f28cd5
updated_with_bug_fix_and_process_trxs
Kron1749 Nov 21, 2024
47e7cde
Merge branch 'master' into feature/mst-account
Kron1749 Nov 21, 2024
3b21a0b
updated_other_way_to_deep_clone
Kron1749 Nov 21, 2024
a614ea4
fixed_getting_proper_mst_account
Kron1749 Nov 22, 2024
e685b0f
updated_with_new_processing_trxs
Kron1749 Nov 25, 2024
48451b1
updated_with_parse_trxs
Kron1749 Nov 28, 2024
e3382b2
Merge branch 'master' into feature/mst-account
Kron1749 Nov 28, 2024
d625d11
fixed_script_error
Kron1749 Nov 28, 2024
29c7bac
updated_with_new_version
Kron1749 Dec 2, 2024
eb06d41
updated_with_builded_files
Kron1749 Dec 2, 2024
75e5755
reversed_to_previously_version
Kron1749 Dec 2, 2024
e917aed
updated_with_fixed_amount_of_fee
Kron1749 Dec 3, 2024
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
39 changes: 39 additions & 0 deletions packages/sdk/src/apiAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,43 @@ export class ApiAccount<T = void> extends WithAccountHistory implements ISubmitE
return '0';
}
}

public createMST(accounts: string[], threshold: number, name: string): string {
const result = keyring.addMultisig(accounts, threshold, { name });
const addressMST = this.formatAddress(result.pair.address);
keyring.saveAddress(addressMST, {
name,
isMultisig: true,
whenCreated: Date.now(),
threshold,
who: accounts,
});
// In default account set MST Address account
this.accountStorage?.set('MSTAddress', addressMST);

return addressMST;
}

public getMstAccount(address: string): KeyringAddress | undefined {
const multisigAccounts = keyring.getAddresses().filter(({ meta }) => meta.isMultisig);
const multisigAccount = multisigAccounts.find((account) => {
const accountAddress = this.formatAddress(account.address, false);
const targetAddress = this.formatAddress(address, false);
return accountAddress === targetAddress;
});
return multisigAccount;
}

public updateMultisigName(newName: string): void {
const addressMST = this.formatAddress(this.account?.pair?.address) ?? '';
Kron1749 marked this conversation as resolved.
Show resolved Hide resolved
const multisigAccount = this.getMstAccount(addressMST);
if (multisigAccount) {
const pair = keyring.getPair(multisigAccount.address);
Kron1749 marked this conversation as resolved.
Show resolved Hide resolved
const currentMeta = pair.meta || {};
const updatedMeta = { ...currentMeta, name: newName };
keyring.saveAccountMeta(pair, updatedMeta);
} else {
console.error(`Multisig account with address ${addressMST} not found among multisig accounts.`);
}
}
}
61 changes: 61 additions & 0 deletions packages/sdk/src/mstTransfers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,65 @@ export class MstTransfersModule<T> {
return null;
}
}

getMSTName(): string {
const addressMST = this.root.account?.pair?.address ?? '';
const multisigAccount = this.root.getMstAccount(addressMST);
return multisigAccount?.meta.name ?? '';
}

public isMstAddressExist(): boolean {
/* We taking previousAccountAddress because for now we are in MST,
and we have MST address stored onle in default account
previousAccountAddress have only MST*/
const addressMST =
(this.root.accountStorage?.get('previousAccountAddress') || this.root.accountStorage?.get('MSTAddress')) ?? '';
return addressMST !== '';
}

public isMST(): boolean {
const addressMST = this.root.accountStorage?.get('previousAccountAddress');
return addressMST !== '';
}

public forgetMSTAccount(): void {
// We will be always in MST before delete it
const previousAccountAddress = this.root.accountStorage?.get('previousAccountAddress');
const previousAccountPair = this.root.getAccountPair(previousAccountAddress ?? '');
const meta = previousAccountPair.meta;
const mstAddress = this.root.address;

this.root.accountStorage?.remove('previousAccountAddress');
this.root.accountStorage?.remove('assetsAddresses');
// Login to the default account
this.root.loginAccount(
previousAccountPair.address,
meta.name as string,
meta.source as string,
meta.isExternal as boolean
);
this.root.accountStorage?.remove('MSTAddress');
this.root.forgetAccount(mstAddress);
}

public switchAccount(switchToMST: boolean): void {
const currentAccountAddress = this.root.account?.pair?.address ?? '';
let targetAddress: string | undefined;
let storePreviousAccountAddress = false;

if (switchToMST) {
targetAddress = this.root.accountStorage?.get('MSTAddress');
storePreviousAccountAddress = true;
} else {
targetAddress = this.root.accountStorage?.get('previousAccountAddress');
}

const accountPair = this.root.getAccountPair(targetAddress ?? '');
const meta = accountPair.meta;
this.root.loginAccount(accountPair.address, meta.name as string, meta.source as string, meta.isExternal as boolean);

if (storePreviousAccountAddress) {
this.root.accountStorage?.set('previousAccountAddress', currentAccountAddress);
}
}
}