fix: change gateway and remove old code to decode the hash

Fixes:
- https://github.com/status-im/status-desktop/issues/6964
Depends on:
- https://github.com/status-im/status-go/pull/2795
- https://github.com/status-im/status-jenkins-lib/pull/44

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jonathan Rainville 2022-08-10 15:18:20 -04:00 committed by Jakub Sokołowski
parent b657d0aede
commit 7544bd6fb5
No known key found for this signature in database
GPG Key ID: 09AA5403E54D9931
27 changed files with 32 additions and 95 deletions

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { agent {

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { agent {

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { agent {

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { agent {

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { label 'windows' } agent { label 'windows' }

View File

@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.4' library 'status-jenkins-lib@v1.5.1'
pipeline { pipeline {
agent { agent {

View File

@ -102,9 +102,6 @@ proc dismissActivityCenterNotifications*(self: Controller, notificationIds: seq[
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): string = proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): string =
return self.messageService.getRenderedText(parsedTextArray) return self.messageService.getRenderedText(parsedTextArray)
proc decodeContentHash*(self: Controller, hash: string): string =
return eth_utils.decodeContentHash(hash)
proc switchTo*(self: Controller, sectionId, chatId, messageId: string) = proc switchTo*(self: Controller, sectionId, chatId, messageId: string) =
let data = ActiveSectionChatArgs(sectionId: sectionId, chatId: chatId, messageId: messageId) let data = ActiveSectionChatArgs(sectionId: sectionId, chatId: chatId, messageId: messageId)
self.events.emit(SIGNAL_MAKE_SECTION_CHAT_ACTIVE, data) self.events.emit(SIGNAL_MAKE_SECTION_CHAT_ACTIVE, data)

View File

@ -88,7 +88,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
message.timestamp, message.timestamp,
ContentType(message.contentType), ContentType(message.contentType),
message.messageType, message.messageType,
self.controller.decodeContentHash(message.sticker.hash), message.sticker.url,
message.sticker.pack, message.sticker.pack,
message.links, message.links,
newTransactionParametersItem("","","","","","",-1,""), newTransactionParametersItem("","","","","","",-1,""),

View File

@ -235,9 +235,6 @@ proc getCurrentFleet*(self: Controller): string =
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): string = proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): string =
return self.messageService.getRenderedText(parsedTextArray) return self.messageService.getRenderedText(parsedTextArray)
proc decodeContentHash*(self: Controller, hash: string): string =
return eth_utils.decodeContentHash(hash)
proc getTransactionDetails*(self: Controller, message: MessageDto): (string,string) = proc getTransactionDetails*(self: Controller, message: MessageDto): (string,string) =
return self.messageService.getTransactionDetails(message) return self.messageService.getTransactionDetails(message)

View File

@ -227,9 +227,6 @@ proc getMessageDetails*(self: Controller, messageId: string):
proc deleteMessage*(self: Controller, messageId: string) = proc deleteMessage*(self: Controller, messageId: string) =
self.messageService.deleteMessage(messageId) self.messageService.deleteMessage(messageId)
proc decodeContentHash*(self: Controller, hash: string): string =
return eth_utils.decodeContentHash(hash)
proc editMessage*(self: Controller, messageId: string, updatedMsg: string) = proc editMessage*(self: Controller, messageId: string, updatedMsg: string) =
self.messageService.editMessage(messageId, updatedMsg) self.messageService.editMessage(messageId, updatedMsg)

View File

@ -192,7 +192,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.whisperTimestamp, m.whisperTimestamp,
m.contentType.ContentType, m.contentType.ContentType,
m.messageType, m.messageType,
sticker = self.controller.decodeContentHash(m.sticker.hash), sticker = m.sticker.url,
m.sticker.pack, m.sticker.pack,
m.links, m.links,
newTransactionParametersItem(m.transactionParameters.id, newTransactionParametersItem(m.transactionParameters.id,
@ -281,7 +281,7 @@ method messageAdded*(self: Module, message: MessageDto) =
message.whisperTimestamp, message.whisperTimestamp,
message.contentType.ContentType, message.contentType.ContentType,
message.messageType, message.messageType,
sticker = self.controller.decodeContentHash(message.sticker.hash), sticker = message.sticker.url,
message.sticker.pack, message.sticker.pack,
message.links, message.links,
newTransactionParametersItem(message.transactionParameters.id, newTransactionParametersItem(message.transactionParameters.id,

View File

@ -180,7 +180,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
m.timestamp, m.timestamp,
m.contentType.ContentType, m.contentType.ContentType,
m.messageType, m.messageType,
self.controller.decodeContentHash(m.sticker.hash), m.sticker.url,
m.sticker.pack, m.sticker.pack,
m.links, m.links,
newTransactionParametersItem(m.transactionParameters.id, newTransactionParametersItem(m.transactionParameters.id,

View File

@ -124,9 +124,6 @@ proc sendSticker*(
preferredUsername: string) = preferredUsername: string) =
self.stickerService.sendSticker(channelId, replyTo, sticker, preferredUsername) self.stickerService.sendSticker(channelId, replyTo, sticker, preferredUsername)
proc decodeContentHash*(self: Controller, hash: string): string =
eth_utils.decodeContentHash(hash)
proc wei2Eth*(self: Controller, price: Stuint[256]): string = proc wei2Eth*(self: Controller, price: Stuint[256]): string =
eth_utils.wei2Eth(price) eth_utils.wei2Eth(price)

View File

@ -49,9 +49,6 @@ method installStickerPack*(self: AccessInterface, packId: string) {.base.} =
method uninstallStickerPack*(self: AccessInterface, packId: string) {.base.} = method uninstallStickerPack*(self: AccessInterface, packId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method decodeContentHash*(self: AccessInterface, hash: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method wei2Eth*(self: AccessInterface, price: Stuint[256]): string {.base.} = method wei2Eth*(self: AccessInterface, price: Stuint[256]): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -73,9 +73,6 @@ method uninstallStickerPack*(self: Module, packId: string) =
method removeRecentStickers*(self: Module, packId: string) = method removeRecentStickers*(self: Module, packId: string) =
self.controller.removeRecentStickers(packId) self.controller.removeRecentStickers(packId)
method decodeContentHash*(self: Module, hash: string): string =
self.controller.decodeContentHash(hash)
method wei2Eth*(self: Module, price: Stuint[256]): string = method wei2Eth*(self: Module, price: Stuint[256]): string =
self.controller.wei2Eth(price) self.controller.wei2Eth(price)

View File

@ -123,8 +123,8 @@ QtObject:
self.stickerPacksLoaded() self.stickerPacksLoaded()
self.installedStickerPacksUpdated() self.installedStickerPacksUpdated()
proc send*(self: View, channelId: string, hash: string, replyTo: string, pack: string) {.slot.} = proc send*(self: View, channelId: string, hash: string, replyTo: string, pack: string, url: string) {.slot.} =
let sticker = initItem(hash, pack, eth_utils.decodeContentHash(hash)) let sticker = initItem(hash, pack, url)
self.addRecentStickerToList(sticker) self.addRecentStickerToList(sticker)
self.delegate.sendSticker(channelId, replyTo, sticker) self.delegate.sendSticker(channelId, replyTo, sticker)

View File

@ -13,58 +13,6 @@ import ../../common/conversion as common_conversion
export common_conversion export common_conversion
proc decodeContentHash*(value: string): string =
if value == "":
return ""
# eg encoded sticker multihash cid:
# e30101701220eab9a8ef4eac6c3e5836a3768d8e04935c10c67d9a700436a0e53199e9b64d29
# e3017012205c531b83da9dd91529a4cf8ecd01cb62c399139e6f767e397d2f038b820c139f (testnet)
# e3011220c04c617170b1f5725070428c01280b4c19ae9083b7e6d71b7a0d2a1b5ae3ce30 (testnet)
#
# The first 4 bytes (in hex) represent:
# e3 = codec identifier "ipfs-ns" for content-hash
# 01 = unused - sometimes this is NOT included (ie ropsten)
# 01 = CID version (effectively unused, as we will decode with CIDv0 regardless)
# 70 = codec identifier "dag-pb"
# ipfs-ns
if value[0..1] != "e3":
warn "Could not decode sticker. It may still be valid, but requires a different codec to be used", hash=value
return ""
try:
# dag-pb
let defaultCodec = parseHexInt("70") #dag-pb
var codec = defaultCodec # no codec specified
var codecStartIdx = 2 # idx of where codec would start if it was specified
# handle the case when starts with 0xe30170 instead of 0xe3010170
if value[2..5] == "0101":
codecStartIdx = 6
codec = parseHexInt(value[6..7])
elif value[2..3] == "01" and value[4..5] != "12":
codecStartIdx = 4
codec = parseHexInt(value[4..5])
# strip the info we no longer need
var multiHashStr = value[codecStartIdx + 2..<value.len]
# The rest of the hash identifies the multihash algo, length, and digest
# More info: https://multiformats.io/multihash/
# 12 = identifies sha2-256 hash
# 20 = multihash length = 32
# ...rest = multihash digest
let multiHash = MultiHash.init(nimcrypto.fromHex(multiHashStr)).get()
let resultTyped = Cid.init(CIDv0, MultiCodec.codec(codec), multiHash).get()
let base32Hash = Multibase.encode("base32", resultTyped.data.buffer)
if base32Hash.isOk():
result = "https://" & base32Hash.get() & ".ipfs.infura-ipfs.io" # TODO: eventually this will not be needed, since messages will return the decoded content hash
trace "Decoded sticker hash", cid=result
except Exception as e:
error "Error decoding sticker", hash=value, exception=e.msg
raise
proc isWakuEnabled(): bool = proc isWakuEnabled(): bool =
true # TODO: true # TODO:

View File

@ -30,6 +30,7 @@ type QuotedMessage* = object
type Sticker* = object type Sticker* = object
hash*: string hash*: string
url*: string
pack*: int pack*: int
type GapParameters* = object type GapParameters* = object
@ -100,6 +101,7 @@ proc toSticker*(jsonObj: JsonNode): Sticker =
result = Sticker() result = Sticker()
discard jsonObj.getProp("hash", result.hash) discard jsonObj.getProp("hash", result.hash)
discard jsonObj.getProp("pack", result.pack) discard jsonObj.getProp("pack", result.pack)
discard jsonObj.getProp("url", result.url)
proc toGapParameters*(jsonObj: JsonNode): GapParameters = proc toGapParameters*(jsonObj: JsonNode): GapParameters =
result = GapParameters() result = GapParameters()

View File

@ -17,6 +17,7 @@ QtObject {
property bool createChatStartReceiveTransactionProcess: false property bool createChatStartReceiveTransactionProcess: false
property string createChatStickerHashId: "" property string createChatStickerHashId: ""
property string createChatStickerPackId: "" property string createChatStickerPackId: ""
property string createChatStickerUrl: ""
property var groupInfoPopupComponent property var groupInfoPopupComponent
property var membershipRequestPopup property var membershipRequestPopup
@ -175,8 +176,8 @@ QtObject {
} }
} }
function sendSticker(channelId, hash, replyTo, pack) { function sendSticker(channelId, hash, replyTo, pack, url) {
stickersModuleInst.send(channelId, hash, replyTo, pack) stickersModuleInst.send(channelId, hash, replyTo, pack, url)
} }
function copyToClipboard(text) { function copyToClipboard(text) {

View File

@ -118,11 +118,13 @@ Item {
Global.openPopup(cmpReceiveTransaction); Global.openPopup(cmpReceiveTransaction);
} }
else if (root.rootStore.createChatStickerHashId !== "" && else if (root.rootStore.createChatStickerHashId !== "" &&
root.rootStore.createChatStickerPackId !== "") { root.rootStore.createChatStickerPackId !== "" &&
root.rootStore.createChatStickerUrl !== "") {
root.rootStore.sendSticker(chatId, root.rootStore.sendSticker(chatId,
root.rootStore.createChatStickerHashId, root.rootStore.createChatStickerHashId,
"", "",
root.rootStore.createChatStickerPackId); root.rootStore.createChatStickerPackId,
root.rootStore.createChatStickerUrl);
} }
else if (root.rootStore.createChatInitMessage !== "" || else if (root.rootStore.createChatInitMessage !== "" ||
root.rootStore.createChatFileUrls.length > 0) { root.rootStore.createChatFileUrls.length > 0) {

View File

@ -516,7 +516,8 @@ ColumnLayout {
root.rootStore.sendSticker(chatContentModule.getMyChatId(), root.rootStore.sendSticker(chatContentModule.getMyChatId(),
hashId, hashId,
chatInput.isReply ? chatInput.replyMessageId : "", chatInput.isReply ? chatInput.replyMessageId : "",
packId) packId,
url)
} }

View File

@ -167,6 +167,7 @@ Page {
onStickerSelected: { onStickerSelected: {
root.rootStore.createChatStickerHashId = hashId; root.rootStore.createChatStickerHashId = hashId;
root.rootStore.createChatStickerPackId = packId; root.rootStore.createChatStickerPackId = packId;
root.rootStore.createChatStickerUrl = url;
root.createChat(); root.createChat();
} }

View File

@ -27,7 +27,7 @@ Rectangle {
signal sendTransactionCommandButtonClicked() signal sendTransactionCommandButtonClicked()
signal receiveTransactionCommandButtonClicked() signal receiveTransactionCommandButtonClicked()
signal stickerSelected(string hashId, string packId) signal stickerSelected(string hashId, string packId, string url)
signal sendMessage(var event) signal sendMessage(var event)
signal unblockChat() signal unblockChat()
@ -815,7 +815,7 @@ Rectangle {
recentStickers: control.recentStickers recentStickers: control.recentStickers
stickerPackList: control.stickerPackList stickerPackList: control.stickerPackList
onStickerSelected: { onStickerSelected: {
control.stickerSelected(hashId, packId) control.stickerSelected(hashId, packId, url)
control.hideExtendedArea(); control.hideExtendedArea();
messageInputField.forceActiveFocus(); messageInputField.forceActiveFocus();
} }

View File

@ -19,7 +19,7 @@ StatusGridView {
cellHeight: 88 cellHeight: 88
model: stickerList model: stickerList
focus: true focus: true
signal stickerClicked(string hash, int packId) signal stickerClicked(string hash, int packId, string url)
delegate: Item { delegate: Item {
width: root.cellWidth width: root.cellWidth
height: root.cellHeight height: root.cellHeight
@ -32,7 +32,7 @@ StatusGridView {
height: 80 height: 80
source: url source: url
onClicked: { onClicked: {
root.stickerClicked(hash, packId) root.stickerClicked(hash, packId, url)
} }
} }
} }

View File

@ -17,7 +17,7 @@ Popup {
property var store property var store
property var recentStickers: StickerData {} property var recentStickers: StickerData {}
property var stickerPackList: StickerPackData {} property var stickerPackList: StickerPackData {}
signal stickerSelected(string hashId, string packId) signal stickerSelected(string hashId, string packId, string url)
property int installedPacksCount: stickersModule.numInstalledStickerPacks property int installedPacksCount: stickersModule.numInstalledStickerPacks
property bool stickerPacksLoaded: false property bool stickerPacksLoaded: false
width: 360 width: 360
@ -172,7 +172,7 @@ Popup {
model: recentStickers model: recentStickers
packId: stickerPackListView.selectedPackId packId: stickerPackListView.selectedPackId
onStickerClicked: { onStickerClicked: {
root.stickerSelected(hash, packId) root.stickerSelected(hash, packId, url)
root.close() root.close()
} }
} }