From d9b1ec488b69edde2c8a515cef36822d65158ff6 Mon Sep 17 00:00:00 2001 From: CalDescent <> Date: Sat, 22 Oct 2022 13:16:17 +0100 Subject: [PATCH] Added chatReference to ChatTransaction and GroupChatTransaction. Since this affects transaction serialization, it will need to take effect from a future undecided timestamp (defined in constants.js), and both core & UI will need to share the same timestamp. The feature trigger timestamp comparisons can be removed 24 hours (or more) post-activation. This is because CHAT messages are currently discarded after 24 hours so we don't need to maintain backwards support of the old serialization approach. The feature trigger is only to ensure full chat operation during the 24 hours that the switchover occurs. --- qortal-ui-crypto/api/constants.js | 6 ++++-- .../api/transactions/chat/ChatTransaction.js | 20 +++++++++++++++++++ .../transactions/chat/GroupChatTransaction.js | 20 +++++++++++++++++++ .../plugins/core/components/ChatModals.js | 1 + .../plugins/core/components/ChatPage.js | 2 ++ .../core/components/ChatWelcomePage.js | 1 + .../plugins/core/components/NameMenu.js | 1 + .../core/messaging/q-chat/q-chat.src.js | 1 + 8 files changed, 50 insertions(+), 2 deletions(-) diff --git a/qortal-ui-crypto/api/constants.js b/qortal-ui-crypto/api/constants.js index 1909fffc..b3fa7cd4 100644 --- a/qortal-ui-crypto/api/constants.js +++ b/qortal-ui-crypto/api/constants.js @@ -249,6 +249,8 @@ const ERROR_CODES = { 1000: "Not yet released." } +const CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP = 9999999999999 + const QORT_DECIMALS = 1e8 const PROXY_URL = "/proxy/" // Proxy for api calls @@ -265,7 +267,7 @@ const STATIC_BCRYPT_SALT = `$${BCRYPT_VERSION}$${BCRYPT_ROUNDS}$IxVE941tXVUD4cW0 const KDF_THREADS = 16 // 16 Threads seems like a good number :) . No you dumbass nigerian. Its not ! -_- -export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT } +export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT, CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } //const TX_TYPES = { // GENESIS_TRANSACTION: 1, @@ -291,4 +293,4 @@ export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_V // DEPLOY_AT_TRANSACTION: 16, // // MESSAGE_TRANSACTION: 17 -//}; \ No newline at end of file +//}; diff --git a/qortal-ui-crypto/api/transactions/chat/ChatTransaction.js b/qortal-ui-crypto/api/transactions/chat/ChatTransaction.js index 6e6dcfd4..a53a0f81 100644 --- a/qortal-ui-crypto/api/transactions/chat/ChatTransaction.js +++ b/qortal-ui-crypto/api/transactions/chat/ChatTransaction.js @@ -3,6 +3,7 @@ import ChatBase from "./ChatBase.js" import nacl from '../../deps/nacl-fast.js' import ed2curve from '../../deps/ed2curve.js' import { Sha256 } from 'asmcrypto.js' +import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js' export default class ChatTransaction extends ChatBase { @@ -29,6 +30,15 @@ export default class ChatTransaction extends ChatBase { this._hasReceipient[0] = 1 } + set hasChatReference(hasChatReference) { + this._hasChatReference = new Uint8Array(1) + this._hasChatReference[0] = hasChatReference + } + + set chatReference(chatReference) { + this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference) + } + set message(message) { this.messageText = message; @@ -72,6 +82,16 @@ export default class ChatTransaction extends ChatBase { this._isText, this._feeBytes ) + + // After the feature trigger timestamp we need to include chat reference + if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) { + params.push(this._hasChatReference) + + if (this._hasChatReference[0] == 1) { + params.push(this._chatReference) + } + } + return params; } } diff --git a/qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js b/qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js index efbd97b0..4f0f2386 100644 --- a/qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js +++ b/qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js @@ -1,5 +1,6 @@ "use strict"; import ChatBase from "./ChatBase.js" +import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js' export default class GroupChatTransaction extends ChatBase { constructor() { @@ -18,6 +19,15 @@ export default class GroupChatTransaction extends ChatBase { this._hasReceipient[0] = hasReceipient } + set hasChatReference(hasChatReference) { + this._hasChatReference = new Uint8Array(1) + this._hasChatReference[0] = hasChatReference + } + + set chatReference(chatReference) { + this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference) + } + set message(message) { this.messageText = message; @@ -47,6 +57,16 @@ export default class GroupChatTransaction extends ChatBase { this._isText, this._feeBytes ) + + // After the feature trigger timestamp we need to include chat reference + if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) { + params.push(this._hasChatReference) + + if (this._hasChatReference[0] == 1) { + params.push(this._chatReference) + } + } + return params; } } diff --git a/qortal-ui-plugins/plugins/core/components/ChatModals.js b/qortal-ui-plugins/plugins/core/components/ChatModals.js index c1ce0b2d..ab772335 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatModals.js +++ b/qortal-ui-plugins/plugins/core/components/ChatModals.js @@ -183,6 +183,7 @@ class ChatModals extends LitElement { timestamp: sendTimestamp, recipient: recipient, recipientPublicKey: _publicKey, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0, diff --git a/qortal-ui-plugins/plugins/core/components/ChatPage.js b/qortal-ui-plugins/plugins/core/components/ChatPage.js index aba20938..6c0e192c 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatPage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatPage.js @@ -667,6 +667,7 @@ class ChatPage extends LitElement { timestamp: Date.now(), recipient: this._chatId, recipientPublicKey: this._publicKey.key, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0, @@ -684,6 +685,7 @@ class ChatPage extends LitElement { timestamp: Date.now(), groupID: Number(this._chatId), hasReceipient: 0, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0, diff --git a/qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js b/qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js index 1d9ea9bc..782db47f 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js @@ -410,6 +410,7 @@ class ChatWelcomePage extends LitElement { timestamp: sendTimestamp, recipient: recipient, recipientPublicKey: _publicKey, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0, diff --git a/qortal-ui-plugins/plugins/core/components/NameMenu.js b/qortal-ui-plugins/plugins/core/components/NameMenu.js index 77472b71..17c39a88 100644 --- a/qortal-ui-plugins/plugins/core/components/NameMenu.js +++ b/qortal-ui-plugins/plugins/core/components/NameMenu.js @@ -529,6 +529,7 @@ class NameMenu extends LitElement { timestamp: sendTimestamp, recipient: recipient, recipientPublicKey: _publicKey, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0, diff --git a/qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js b/qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js index a6dc0244..0eddc863 100644 --- a/qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js +++ b/qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js @@ -819,6 +819,7 @@ class Chat extends LitElement { timestamp: sendTimestamp, recipient: recipient, recipientPublicKey: _publicKey, + hasChatReference: 0, message: messageText, lastReference: reference, proofOfWorkNonce: 0,