From 5ba894a6f149cfa31728b9d900bb0ab6ec28fa38 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 24 Jan 2023 22:50:34 +0500 Subject: [PATCH] linked up bugsnag reporting with sendHiveOperations and a handful of activeKey operations --- src/providers/hive/dhive.js | 93 +++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index a23c917be..46a878038 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -85,32 +85,41 @@ export const sendHiveOperations = async ( operations: Operation[], key: PrivateKey | PrivateKey[], ): Promise => { - const { head_block_number, head_block_id, time } = await getDynamicGlobalProperties(); - const ref_block_num = head_block_number & 0xffff; - const ref_block_prefix = Buffer.from(head_block_id, 'hex').readUInt32LE(4); - const expireTime = 60 * 1000; - const chainId = Buffer.from( - 'beeab0de00000000000000000000000000000000000000000000000000000000', - 'hex', - ); - const expiration = new Date(new Date(`${time}Z`).getTime() + expireTime) - .toISOString() - .slice(0, -5); - const extensions = []; + try { + const { head_block_number, head_block_id, time } = await getDynamicGlobalProperties(); + const ref_block_num = head_block_number & 0xffff; + const ref_block_prefix = Buffer.from(head_block_id, 'hex').readUInt32LE(4); + const expireTime = 60 * 1000; + const chainId = Buffer.from( + 'beeab0de00000000000000000000000000000000000000000000000000000000', + 'hex', + ); + const expiration = new Date(new Date(`${time}Z`).getTime() + expireTime) + .toISOString() + .slice(0, -5); + const extensions = []; - const tx: Transaction = { - expiration, - extensions, - operations, - ref_block_num, - ref_block_prefix, - }; + const tx: Transaction = { + expiration, + extensions, + operations, + ref_block_num, + ref_block_prefix, + }; + + const transaction = await cryptoUtils.signTransaction(tx, key, chainId); + const trxId = generateTrxId(transaction); + const resultHive = await client.broadcast.call('broadcast_transaction', [transaction]); + const result = Object.assign({ id: trxId }, resultHive); + return result; + } catch(err){ + bugsnagInstance.notify(err, (event)=>{ + event.context = 'send-hive-operations' + event.setMetaData('operationsArray', operations) + }); + throw err; + } - const transaction = await cryptoUtils.signTransaction(tx, key, chainId); - const trxId = generateTrxId(transaction); - const resultHive = await client.broadcast.call('broadcast_transaction', [transaction]); - const result = Object.assign({ id: trxId }, resultHive); - return result; }; /** reuseable broadcast json method with posting auth */ @@ -1732,11 +1741,15 @@ export const transferPoint = (currentAccount, pinCode, data) => { }; const opArray = [['custom_json', op]]; return sendHiveOperations(opArray, privateKey); + } else { + const err = new Error('Check private key permission! Required private active key or above.') + bugsnagInstance.notify(err, (event) => { + event.setUser(currentAccount.username) + event.context('ransfer-points') + event.setMetaData('encryptedLocal', currentAccount.local) + }) + return Promise.reject(err); } - - return Promise.reject( - new Error('Check private key permission! Required private active key or above.'), - ); }; export const promote = (currentAccount, pinCode, duration, permlink, author) => { @@ -1761,11 +1774,15 @@ export const promote = (currentAccount, pinCode, duration, permlink, author) => const opArray = [['custom_json', json]]; return sendHiveOperations(opArray, privateKey); + } else { + const err = new Error('Check private key permission! Required private active key or above.') + bugsnagInstance.notify(err, (event) => { + event.setUser(currentAccount.username) + event.context('promoting-content') + event.setMetaData('encryptedLocal', currentAccount.local) + }) + return Promise.reject(err); } - - return Promise.reject( - new Error('Check private key permission! Required private active key or above.'), - ); }; export const boost = (currentAccount, pinCode, point, permlink, author) => { @@ -1790,11 +1807,17 @@ export const boost = (currentAccount, pinCode, point, permlink, author) => { const opArray = [['custom_json', json]]; return sendHiveOperations(opArray, privateKey); + } else { + const err = new Error('Check private key permission! Required private active key or above.') + bugsnagInstance.notify(err, (event) => { + event.setUser(currentAccount.username) + event.context('boosting-content') + event.setMetaData('encryptedLocal', currentAccount.local) + }) + return Promise.reject(err); } - return Promise.reject( - new Error('Check private key permission! Required private active key or above.'), - ); + }; export const grantPostingPermission = async (json, pin, currentAccount) => {