Refactor process creation for pairing/profile/folder use cases
This commit is contained in:
parent
e15da5c22a
commit
8eb6f36b64
@ -262,26 +262,13 @@ export default class Services {
|
|||||||
throw new Error('Amount is still 0 after 3 attempts');
|
throw new Error('Amount is still 0 after 3 attempts');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createPairingProcess(userName: string, pairWith: string[], relayAddress: string, feeRate: number): Promise<ApiReturn> {
|
public async createPairingProcess(userName: string, pairWith: string[]): Promise<ApiReturn> {
|
||||||
if (this.sdkClient.is_paired()) {
|
if (this.sdkClient.is_paired()) {
|
||||||
throw new Error('Device already paired');
|
throw new Error('Device already paired');
|
||||||
}
|
}
|
||||||
const myAddress: string = this.sdkClient.get_address();
|
const myAddress: string = this.sdkClient.get_address();
|
||||||
pairWith.push(myAddress);
|
pairWith.push(myAddress);
|
||||||
const roles: Record<string, RoleDefinition> = {
|
const privateData = {
|
||||||
pairing: {
|
|
||||||
members: [],
|
|
||||||
validation_rules: [
|
|
||||||
{
|
|
||||||
quorum: 1.0,
|
|
||||||
fields: ['description', 'counter', 'roles', 'memberPublicName', 'pairedAddresses'],
|
|
||||||
min_sig_member: 1.0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
storages: [STORAGEURL]
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const pairingTemplate = {
|
|
||||||
description: 'pairing',
|
description: 'pairing',
|
||||||
counter: 0,
|
counter: 0,
|
||||||
};
|
};
|
||||||
@ -289,14 +276,25 @@ export default class Services {
|
|||||||
memberPublicName: userName,
|
memberPublicName: userName,
|
||||||
pairedAddresses: pairWith,
|
pairedAddresses: pairWith,
|
||||||
};
|
};
|
||||||
|
const validation_fields: string[] = [...Object.keys(privateData), ...Object.keys(publicData), 'roles'];
|
||||||
|
const roles: Record<string, RoleDefinition> = {
|
||||||
|
pairing: {
|
||||||
|
members: [],
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 1.0,
|
||||||
|
fields: validation_fields,
|
||||||
|
min_sig_member: 1.0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: [STORAGEURL]
|
||||||
|
},
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
return this.sdkClient.create_new_process(
|
return this.createProcess(
|
||||||
pairingTemplate,
|
privateData,
|
||||||
roles,
|
|
||||||
publicData,
|
publicData,
|
||||||
relayAddress,
|
roles
|
||||||
feeRate,
|
|
||||||
this.getAllMembers()
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Creating process failed:, ${e}`);
|
throw new Error(`Creating process failed:, ${e}`);
|
||||||
@ -474,8 +472,15 @@ export default class Services {
|
|||||||
|
|
||||||
delete userData.validator; // We don't want that in the final pcd
|
delete userData.validator; // We don't want that in the final pcd
|
||||||
|
|
||||||
const userDataKeys = Object.keys(userData);
|
const privateData = {
|
||||||
|
description: 'profile',
|
||||||
|
...userData,
|
||||||
|
};
|
||||||
|
const publicData = {
|
||||||
|
identityCertified: false,
|
||||||
|
};
|
||||||
|
const ownerRoleFields: string[] = [...privateData, 'roles'];
|
||||||
|
const validatorRoleFields: string[] = [...publicData];
|
||||||
const roles: Record<string, RoleDefinition> = {
|
const roles: Record<string, RoleDefinition> = {
|
||||||
demiurge: {
|
demiurge: {
|
||||||
members: [myProcessId],
|
members: [myProcessId],
|
||||||
@ -487,11 +492,7 @@ export default class Services {
|
|||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.01,
|
quorum: 0.01,
|
||||||
fields: [
|
fields: ownerRoleFields,
|
||||||
'description',
|
|
||||||
'roles',
|
|
||||||
...userDataKeys
|
|
||||||
],
|
|
||||||
min_sig_member: 0.01,
|
min_sig_member: 0.01,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -502,15 +503,12 @@ export default class Services {
|
|||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 1.0,
|
quorum: 1.0,
|
||||||
fields: ['identityCertified'],
|
fields: validatorRoleFields,
|
||||||
min_sig_member: 1.0
|
min_sig_member: 1.0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
quorum: 0.0,
|
quorum: 0.0,
|
||||||
fields: [
|
fields: ownerRoleFields,
|
||||||
'description',
|
|
||||||
...userDataKeys
|
|
||||||
],
|
|
||||||
min_sig_member: 0.0
|
min_sig_member: 0.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -532,37 +530,15 @@ export default class Services {
|
|||||||
storages: [STORAGEURL]
|
storages: [STORAGEURL]
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const profileTemplate = {
|
|
||||||
description: 'profile',
|
|
||||||
...userData,
|
|
||||||
};
|
|
||||||
const publicData = {
|
|
||||||
identityCertified: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add name and lastName if profile_idn (notary profile)
|
|
||||||
// if (userDataKeys.includes('profile_idn')) {
|
|
||||||
// publicData.identityCertified = true;
|
|
||||||
// publicData.name = userData.name;
|
|
||||||
// publicData.lastName = userData.lastName;
|
|
||||||
// } else {
|
|
||||||
// publicData.identityCertified = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const relayAddress = this.getAllRelays()[0]['spAddress'];
|
|
||||||
const feeRate = 1;
|
|
||||||
|
|
||||||
await this.getTokensFromFaucet();
|
await this.getTokensFromFaucet();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return this.sdkClient.create_new_process(
|
return this.createProcess(
|
||||||
profileTemplate,
|
privateData,
|
||||||
roles,
|
|
||||||
publicData,
|
publicData,
|
||||||
relayAddress,
|
roles,
|
||||||
feeRate,
|
)
|
||||||
this.getAllMembers()
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Creating process failed:, ${e}`);
|
throw new Error(`Creating process failed:, ${e}`);
|
||||||
}
|
}
|
||||||
@ -575,7 +551,14 @@ export default class Services {
|
|||||||
throw new Error('Missing pairing id');
|
throw new Error('Missing pairing id');
|
||||||
}
|
}
|
||||||
|
|
||||||
const folderDataKeys = Object.keys(folderData);
|
const privateData = {
|
||||||
|
description: 'folder',
|
||||||
|
documents: [],
|
||||||
|
notes: [],
|
||||||
|
...folderData,
|
||||||
|
};
|
||||||
|
const ownerRoleFields = [Object.keys(privateData), 'roles'];
|
||||||
|
const stakeholdersRoleFields = ['documents', 'notes'];
|
||||||
|
|
||||||
const roles: Record<string, RoleDefinition> = {
|
const roles: Record<string, RoleDefinition> = {
|
||||||
owner: {
|
owner: {
|
||||||
@ -583,11 +566,7 @@ export default class Services {
|
|||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.01,
|
quorum: 0.01,
|
||||||
fields: [
|
fields: ownerRoleFields,
|
||||||
'description',
|
|
||||||
'roles',
|
|
||||||
...folderDataKeys
|
|
||||||
],
|
|
||||||
min_sig_member: 0.01,
|
min_sig_member: 0.01,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -598,7 +577,7 @@ export default class Services {
|
|||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.01,
|
quorum: 0.01,
|
||||||
fields: ['documents', 'notes'],
|
fields: stakeholdersRoleFields,
|
||||||
min_sig_member: 0.01,
|
min_sig_member: 0.01,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -609,7 +588,7 @@ export default class Services {
|
|||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.0,
|
quorum: 0.0,
|
||||||
fields: ['documents', 'notes'],
|
fields: stakeholdersRoleFields,
|
||||||
min_sig_member: 0.0,
|
min_sig_member: 0.0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -617,31 +596,14 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const folderTemplate = {
|
|
||||||
description: 'folder',
|
|
||||||
...folderData,
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('🚀 ~ Services ~ createFolderProcess ~ folderTemplate:', folderTemplate);
|
|
||||||
|
|
||||||
const publicData = {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const relayAddress = this.getAllRelays()[0]['spAddress'];
|
|
||||||
const feeRate = 1;
|
|
||||||
|
|
||||||
await this.getTokensFromFaucet();
|
await this.getTokensFromFaucet();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return this.sdkClient.create_new_process(
|
return this.getProcess(
|
||||||
folderTemplate,
|
privateData,
|
||||||
roles,
|
{},
|
||||||
publicData,
|
roles
|
||||||
relayAddress,
|
)
|
||||||
feeRate,
|
|
||||||
this.getAllMembers()
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Creating folder process failed: ${e}`);
|
throw new Error(`Creating folder process failed: ${e}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user