conform service.ts to new message format

This commit is contained in:
Sosthene 2024-05-27 14:42:32 +02:00
parent 184d4af31f
commit 1f689d33c3
2 changed files with 12 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { createUserReturn, User, Process, createTransactionReturn, parse_network_msg, outputs_list, FaucetMessage, AnkFlag, NewTxMessage, encryptWithNewKeyResult, AnkSharedSecret, CachedMessage, UnknownMessage } from '../dist/pkg/sdk_client'; import { createUserReturn, User, Process, createTransactionReturn, outputs_list, FaucetMessage, AnkFlag, NewTxMessage, CipherMessage, CachedMessage } from '../dist/pkg/sdk_client';
import IndexedDB from './database' import IndexedDB from './database'
import { WebSocketClient } from './websockets'; import { WebSocketClient } from './websockets';
@ -105,7 +105,7 @@ class Services {
const recipientSpAddress = spAddressElement.value; const recipientSpAddress = spAddressElement.value;
const message = messageElement.value; const message = messageElement.value;
const msg_payload: UnknownMessage = {sender: this.sp_address!, message: message}; const msg_payload: CipherMessage = {sender: this.sp_address!, message: message, error: null};
let notificationInfo = await services.notify_address_for_message(recipientSpAddress, msg_payload); let notificationInfo = await services.notify_address_for_message(recipientSpAddress, msg_payload);
if (notificationInfo) { if (notificationInfo) {
@ -113,7 +113,7 @@ class Services {
console.debug(networkMsg); console.debug(networkMsg);
const connection = await services.pickWebsocketConnectionRandom(); const connection = await services.pickWebsocketConnectionRandom();
const flag: AnkFlag = "Unknown"; const flag: AnkFlag = 'Cipher';
try { try {
// send message (transaction in envelope) // send message (transaction in envelope)
await services.updateMessages(networkMsg); await services.updateMessages(networkMsg);
@ -763,6 +763,7 @@ class Services {
let faucetMsg: FaucetMessage = { let faucetMsg: FaucetMessage = {
sp_address: cachedMsg.recipient, sp_address: cachedMsg.recipient,
commitment: cachedMsg.commitment, commitment: cachedMsg.commitment,
error: null,
} }
connection.sendMessage(flag, JSON.stringify(faucetMsg)); connection.sendMessage(flag, JSON.stringify(faucetMsg));
} }
@ -836,7 +837,8 @@ class Services {
const flag: AnkFlag = "NewTx"; const flag: AnkFlag = "NewTx";
const newTxMsg: NewTxMessage = { const newTxMsg: NewTxMessage = {
'transaction': notificationInfo.transaction, 'transaction': notificationInfo.transaction,
'tweak_data': null 'tweak_data': null,
'error': null,
} }
connection.sendMessage(flag, JSON.stringify(newTxMsg)); connection.sendMessage(flag, JSON.stringify(newTxMsg));
await services.updateMessages(notificationInfo.new_network_msg); await services.updateMessages(notificationInfo.new_network_msg);
@ -871,14 +873,15 @@ class Services {
const flag: AnkFlag = "NewTx"; const flag: AnkFlag = "NewTx";
const newTxMsg: NewTxMessage = { const newTxMsg: NewTxMessage = {
'transaction': notificationInfo.transaction, 'transaction': notificationInfo.transaction,
'tweak_data': null 'tweak_data': null,
'error': null,
} }
connection.sendMessage(flag, JSON.stringify(newTxMsg)); connection.sendMessage(flag, JSON.stringify(newTxMsg));
await services.updateMessages(notificationInfo.new_network_msg); await services.updateMessages(notificationInfo.new_network_msg);
return; return;
} }
public async notify_address_for_message(sp_address: string, message: UnknownMessage): Promise<createTransactionReturn> { public async notify_address_for_message(sp_address: string, message: CipherMessage): Promise<createTransactionReturn> {
const services = await Services.getInstance(); const services = await Services.getInstance();
const connection = await services.pickWebsocketConnectionRandom(); const connection = await services.pickWebsocketConnectionRandom();
if (!connection) { if (!connection) {
@ -891,7 +894,8 @@ class Services {
const flag: AnkFlag = "NewTx"; const flag: AnkFlag = "NewTx";
const newTxMsg: NewTxMessage = { const newTxMsg: NewTxMessage = {
'transaction': notificationInfo.transaction, 'transaction': notificationInfo.transaction,
'tweak_data': null 'tweak_data': null,
'error': null,
} }
connection.sendMessage(flag, JSON.stringify(newTxMsg)); connection.sendMessage(flag, JSON.stringify(newTxMsg));
console.info('Successfully sent notification transaction'); console.info('Successfully sent notification transaction');

View File

@ -31,11 +31,7 @@ class WebSocketClient {
// By parsing the message, we can link it with existing cached message and return the updated version of the message // By parsing the message, we can link it with existing cached message and return the updated version of the message
let res: CachedMessage = await services.parseNetworkMessage(msgData, feeRate); let res: CachedMessage = await services.parseNetworkMessage(msgData, feeRate);
console.debug(res); console.debug(res);
if (res.status === 'Error') { if (res.status === 'FaucetComplete') {
if (res.error) {
console.error(res.error);
}
} else if (res.status === 'FaucetComplete') {
// we received a faucet tx, there's nothing else to do // we received a faucet tx, there's nothing else to do
window.alert(`New faucet output\n${res.commited_in}`); window.alert(`New faucet output\n${res.commited_in}`);
await services.updateMessages(res); await services.updateMessages(res);