refactor: remove nimbaser and nim-base32 dependencies, use stew modules in their place (#58)

Closes issue #56.
This commit is contained in:
Michael Bradley 2021-09-29 08:42:34 -05:00 committed by GitHub
parent da366ae1cf
commit b2ecbda9e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 48 deletions

6
.gitmodules vendored
View File

@ -76,12 +76,6 @@
[submodule "vendor/nim-task-runner"]
path = vendor/nim-task-runner
url = https://github.com/status-im/nim-task-runner.git
[submodule "vendor/nbaser"]
path = vendor/nbaser
url = https://github.com/D-Nice/nbaser/
[submodule "vendor/nim-base32"]
path = vendor/nim-base32
url = https://github.com/elktree/nim-base32
[submodule "vendor/edn.nim"]
path = vendor/edn.nim
url = https://github.com/status-im/edn.nim

View File

@ -5,7 +5,6 @@ import # std libs
json, json_serialization, chronicles, web3/ethtypes,
stint, strutils
from strutils import parseHexInt, parseInt
import nbaser
import # vendor libs
json_serialization, chronicles, libp2p/[multihash, multicodec, cid], stint,

View File

@ -7,16 +7,14 @@ import statusgo_backend/core
import statusgo_backend/settings as status_settings
import json, json_serialization, sets, strutils
import chronicles
import nbaser
import stew/byteutils
from base32 import nil
from stew/base32 import nil
from stew/base58 import nil
const HTTPS_SCHEME* = "https"
const IPFS_GATEWAY* = ".infura.status.im"
const SWARM_GATEWAY* = "swarm-gateways.net"
const base58* = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
logScope:
topics = "provider-model"
@ -264,19 +262,29 @@ proc postMessage*(self: ProviderModel, message: string): string =
of RequestTypes.APIRequest: self.process(message.toAPIRequest())
else: """{"type":"TODO-IMPLEMENT-THIS"}""" ##################### TODO:
proc ensResourceURL*(self: ProviderModel, ens: string, url: string): (string, string, string, string, bool) =
proc ensResourceURL*(self: ProviderModel, ens: string, url: string):
(string, string, string, string, bool) =
let contentHash = contenthash(ens)
if contentHash == "": # ENS does not have a content hash
return (url, url, HTTPS_SCHEME, "", false)
let decodedHash = contentHash.decodeENSContentHash()
case decodedHash[0]:
of ENSType.IPFS:
let base32Hash = base32.encode(string.fromBytes(base58.decode(decodedHash[1]))).toLowerAscii().replace("=", "")
let
base58bytes = base58.decode(base58.BTCBase58, decodedHash[1])
base32Hash = base32.encode(base32.Base32Lower, base58bytes)
result = (url, base32Hash & IPFS_GATEWAY, HTTPS_SCHEME, "", true)
of ENSType.SWARM:
result = (url, SWARM_GATEWAY, HTTPS_SCHEME, "/bzz:/" & decodedHash[1] & "/", true)
result = (url, SWARM_GATEWAY, HTTPS_SCHEME,
"/bzz:/" & decodedHash[1] & "/", true)
of ENSType.IPNS:
result = (url, decodedHash[1], HTTPS_SCHEME, "", true)
else:
warn "Unknown content for", ens, contentHash

View File

@ -1,8 +1,9 @@
import ens, provider
import stew/byteutils
from base32 import nil
from stew/base32 import nil
from stew/base58 import nil
import chronicles, httpclient, net
import nbaser, strutils
import strutils
import semver
import constants
@ -20,14 +21,21 @@ proc getLatestVersion*(): VersionInfo =
var url: string = ""
let decodedHash = contentHash.decodeENSContentHash()
case decodedHash[0]:
of ENSType.IPFS:
let base32Hash = base32.encode(string.fromBytes(base58.decode(decodedHash[1]))).toLowerAscii().replace("=", "")
let
base58bytes = base58.decode(base58.BTCBase58, decodedHash[1])
base32Hash = base32.encode(base32.Base32Lower, base58bytes)
url = "https://" & base32Hash & IPFS_GATEWAY
of ENSType.SWARM:
url = "https://" & SWARM_GATEWAY & "/bzz:/" & decodedHash[1]
of ENSType.IPNS:
url = "https://" & decodedHash[1]
else:
warn "Unknown content for", contentHash
raise newException(ValueError, "Unknown content for " & contentHash)

1
vendor/nbaser vendored

@ -1 +0,0 @@
Subproject commit 0c989e0d9580b4a6c14e11976dba3a0d503ecfcd

1
vendor/nim-base32 vendored

@ -1 +0,0 @@
Subproject commit 660680c1cbdf6b1294b669fdb8b6e9c89794cb5b