Add createMessagingProcess
This commit is contained in:
parent
b9af99cd02
commit
25e0960354
@ -35,6 +35,10 @@ export async function init() {
|
|||||||
search_div.appendChild(autocomplete_list);
|
search_div.appendChild(autocomplete_list);
|
||||||
search_div.appendChild(dropdown_icon);
|
search_div.appendChild(dropdown_icon);
|
||||||
|
|
||||||
|
// This is temporary
|
||||||
|
// Create a new process with hardcoded members for demonstration purpose
|
||||||
|
await createMessagingProcess();
|
||||||
|
|
||||||
const processes = await getProcesses();
|
const processes = await getProcesses();
|
||||||
for (let process of processes) {
|
for (let process of processes) {
|
||||||
const processName = process['description'];
|
const processName = process['description'];
|
||||||
@ -420,6 +424,38 @@ function goToProcessPage() {
|
|||||||
|
|
||||||
(window as any).goToProcessPage = goToProcessPage;
|
(window as any).goToProcessPage = goToProcessPage;
|
||||||
|
|
||||||
|
async function createMessagingProcess(): Promise<void> {
|
||||||
|
console.log('Creating messaging process');
|
||||||
|
const service = await Services.getInstance();
|
||||||
|
const otherMembers = [
|
||||||
|
{
|
||||||
|
sp_addresses: [
|
||||||
|
"tsp1qqd7snxfh44am8f7a3x36znkh4v0dcagcgakfux488ghsg0tny7degq4gd9q4n4us0cyp82643f2p4jgcmtwknadqwl3waf9zrynl6n7lug5tg73a",
|
||||||
|
"tsp1qqvd8pak9fyz55rxqj90wxazqzwupf2egderc96cn84h3l84z8an9vql85scudrmwvsnltfuy9ungg7pxnhys2ft5wnf2gyr3n4ukvezygswesjuc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sp_addresses: [
|
||||||
|
"tsp1qqgl5vawdey6wnnn2sfydcejsr06uzwsjlfa6p6yr8u4mkqwezsnvyqlazuqmxhxd8crk5eq3wfvdwv4k3tn68mkj2nj72jj39d2ngauu4unfx0q7",
|
||||||
|
"tsp1qqthmj56gj8vvkjzwhcmswftlrf6ye7ukpks2wra92jkehqzrvx7m2q570q5vv6zj6dnxvussx2h8arvrcfwz9sp5hpdzrfugmmzz90pmnganxk28"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sp_addresses: [
|
||||||
|
"tsp1qqwjtxr9jye7d40qxrsmd6h02egdwel6mfnujxzskgxvxphfya4e6qqjq4tsdmfdmtnmccz08ut24q8y58qqh4lwl3w8pvh86shlmavrt0u3smhv2",
|
||||||
|
"tsp1qqwn7tf8q2jhmfh8757xze53vg2zc6x5u6f26h3wyty9mklvcy0wnvqhhr4zppm5uyyte4y86kljvh8r0tsmkmszqqwa3ecf2lxcs7q07d56p8sz5"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const relayAddress = service.getAllRelays().pop();
|
||||||
|
if (!relayAddress) {
|
||||||
|
throw new Error('Empty relay address list');
|
||||||
|
}
|
||||||
|
const feeRate = 1;
|
||||||
|
const apiReturn = await service.createMessagingProcess(otherMembers, relayAddress.spAddress, feeRate);
|
||||||
|
await service.handleApiReturn(apiReturn);
|
||||||
|
}
|
||||||
|
|
||||||
async function getProcesses(): Promise<any[]> {
|
async function getProcesses(): Promise<any[]> {
|
||||||
const service = await Services.getInstance();
|
const service = await Services.getInstance();
|
||||||
const processes = await service.getProcesses();
|
const processes = await service.getProcesses();
|
||||||
|
@ -202,6 +202,62 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async createMessagingProcess(otherMembers: Member[],relayAddress: string, feeRate: number): Promise<ApiReturn> {
|
||||||
|
if (!this.sdkClient.is_paired()) {
|
||||||
|
throw new Error('Device not paired');
|
||||||
|
}
|
||||||
|
const me = await this.getMemberFromDevice();
|
||||||
|
if (!me) {
|
||||||
|
throw new Error('No paired member in device');
|
||||||
|
}
|
||||||
|
const allMembers = [otherMembers, { sp_addresses: me }];
|
||||||
|
const meAndOne = [{ sp_addresses: me }, otherMembers.pop()];
|
||||||
|
const everyOneElse = otherMembers;
|
||||||
|
const messagingTemplate = {
|
||||||
|
description: 'messaging',
|
||||||
|
roles: {
|
||||||
|
public: {
|
||||||
|
members: [allMembers],
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 0.0,
|
||||||
|
fields: ['description', 'roles'],
|
||||||
|
min_sig_member: 0.0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: [storageUrl]
|
||||||
|
},
|
||||||
|
owner: {
|
||||||
|
members: meAndOne,
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 1.0,
|
||||||
|
fields: ['description', 'roles'],
|
||||||
|
min_sig_member: 1.0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: [storageUrl]
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
members: everyOneElse,
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 0.0,
|
||||||
|
fields: ['description', 'roles'],
|
||||||
|
min_sig_member: 0.0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: [storageUrl]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return this.sdkClient.create_new_process(JSON.stringify(messagingTemplate), null, relayAddress, feeRate);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Creating process failed:, ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async createPairingProcess(pairWith: string[], relayAddress: string, feeRate: number): Promise<ApiReturn> {
|
public async createPairingProcess(pairWith: string[], relayAddress: string, feeRate: number): Promise<ApiReturn> {
|
||||||
if (this.sdkClient.is_paired()) {
|
if (this.sdkClient.is_paired()) {
|
||||||
throw new Error('Device already paired');
|
throw new Error('Device already paired');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user