chore(@desktop/general): check for updates updated
- unused `updates.nim` removed from `backend` - `ens.nim` updated accordingly to what we have there before - the way how we're checking for updates is updated
This commit is contained in:
parent
58c9e15365
commit
7ff994a46a
|
@ -1,11 +1,8 @@
|
|||
from stew/base32 import nil
|
||||
from stew/base58 import nil
|
||||
import chronicles, httpclient, net, options
|
||||
import json, chronicles, httpclient, net, options
|
||||
import strutils
|
||||
import semver
|
||||
|
||||
import ../provider/service as provider_service
|
||||
import ../ens/utils as ens_utils
|
||||
import ../../../backend/ens as status_ens
|
||||
|
||||
const APP_UPDATES_ENS* = "desktop.status.eth"
|
||||
const CHECK_VERSION_TIMEOUT_MS* = 5000
|
||||
|
@ -16,31 +13,12 @@ type
|
|||
url*: string
|
||||
|
||||
proc getLatestVersion*(): VersionInfo =
|
||||
let contentHash = ens_utils.getContentHash(APP_UPDATES_ENS)
|
||||
if contentHash.isNone():
|
||||
let response = status_ens.resourceUrl(chainId=1, username=APP_UPDATES_ENS)
|
||||
let host = response.result{"Host"}.getStr
|
||||
if host == "":
|
||||
raise newException(ValueError, "ENS does not have a content hash")
|
||||
|
||||
var url: string = ""
|
||||
|
||||
let decodedHash = ens_utils.decodeENSContentHash(contentHash.get())
|
||||
|
||||
case decodedHash[0]:
|
||||
of ENSType.IPFS:
|
||||
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.get())
|
||||
let url = "https://" & host & response.result{"Path"}.getStr
|
||||
|
||||
# Read version from folder
|
||||
let secureSSLContext = newContext()
|
||||
|
|
|
@ -1,216 +1,37 @@
|
|||
import sequtils
|
||||
import strutils
|
||||
import nimcrypto
|
||||
import json
|
||||
import json_serialization
|
||||
import tables
|
||||
import stew/byteutils
|
||||
import web3/[ethtypes, conversions], stint
|
||||
import chronicles, libp2p/[multihash, multicodec, cid]
|
||||
import json, web3/[conversions, ethtypes]
|
||||
import ./core
|
||||
import response_type
|
||||
|
||||
export response_type
|
||||
|
||||
import ./statusgo_backend/wallet
|
||||
import ./statusgo_backend/accounts as status_accounts
|
||||
import ./statusgo_backend/settings as status_settings
|
||||
import ./statusgo_backend_new/ens as status_ens
|
||||
proc resolver*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_resolver", payload)
|
||||
|
||||
import ./types/[transaction, setting, rpc_response, network_type, network, profile]
|
||||
import ./utils
|
||||
import ./transactions
|
||||
import ./eth/contracts
|
||||
proc ownerOf*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_ownerOf", payload)
|
||||
|
||||
const domain* = ".stateofus.eth"
|
||||
proc contentHash*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_contentHash", payload)
|
||||
|
||||
proc userName*(ensName: string, removeSuffix: bool = false): string =
|
||||
if ensName != "" and ensName.endsWith(domain):
|
||||
if removeSuffix:
|
||||
result = ensName.split(".")[0]
|
||||
else:
|
||||
result = ensName
|
||||
else:
|
||||
if ensName.endsWith(".eth") and removeSuffix:
|
||||
return ensName.split(".")[0]
|
||||
result = ensName
|
||||
proc publicKeyOf*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_publicKeyOf", payload)
|
||||
|
||||
proc addDomain*(username: string): string =
|
||||
if username.endsWith(".eth"):
|
||||
return username
|
||||
else:
|
||||
return username & domain
|
||||
proc addressOf*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_addressOf", payload)
|
||||
|
||||
proc hasNickname*(contact: Profile): bool = contact.localNickname != ""
|
||||
proc expireAt*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_expireAt", payload)
|
||||
|
||||
proc userNameOrAlias*(contact: Profile, removeSuffix: bool = false): string =
|
||||
if(contact.ensName != "" and contact.ensVerified):
|
||||
result = "@" & userName(contact.ensName, removeSuffix)
|
||||
elif(contact.localNickname != ""):
|
||||
result = contact.localNickname
|
||||
else:
|
||||
result = contact.alias
|
||||
proc price*(chainId: int): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId]
|
||||
result = core.callPrivateRPC("ens_price", payload)
|
||||
|
||||
proc resolver*(username: string): string =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.resolver(chainId, username)
|
||||
return res.result.getStr
|
||||
|
||||
proc owner*(username: string): string =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.ownerOf(chainId, username)
|
||||
let address = res.result.getStr
|
||||
if address == "0x0000000000000000000000000000000000000000":
|
||||
return ""
|
||||
|
||||
return address
|
||||
|
||||
proc pubkey*(username: string): string =
|
||||
try:
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.publicKeyOf(chainId, addDomain(username))
|
||||
var key = res.result.getStr
|
||||
key.removePrefix("0x")
|
||||
return "0x04" & key
|
||||
except:
|
||||
return ""
|
||||
|
||||
proc address*(username: string): string =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.addressOf(chainId, username)
|
||||
return res.result.getStr
|
||||
|
||||
proc contenthash*(username: string): string =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.contentHash(chainId, username)
|
||||
return res.result.getStr
|
||||
|
||||
proc getPrice*(): Stuint[256] =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.price(chainId)
|
||||
return fromHex(Stuint[256], res.result.getStr)
|
||||
|
||||
proc releaseEstimateGas*(username: string, address: string, success: var bool): int =
|
||||
let
|
||||
chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
txData = transactions.buildTransaction(parseAddress(address), 0.u256)
|
||||
|
||||
try:
|
||||
let resp = status_ens.releaseEstimate(chainId, txData, username)
|
||||
result = resp.result.getInt
|
||||
success = true
|
||||
except:
|
||||
success = false
|
||||
result = 0
|
||||
|
||||
proc release*(username: string, address: string, gas, gasPrice, password: string, success: var bool): string =
|
||||
let
|
||||
chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
txData = transactions.buildTransaction(
|
||||
parseAddress(address), 0.u256, gas, gasPrice
|
||||
)
|
||||
|
||||
try:
|
||||
let resp = status_ens.release(chainId, txData, password, username)
|
||||
result = resp.result.getStr
|
||||
success = true
|
||||
let ensUsernamesContract = contracts.findContract(chainId, "ens-usernames")
|
||||
trackPendingTransaction(result, address, $ensUsernamesContract.address, PendingTransactionType.ReleaseENS, username)
|
||||
except:
|
||||
success = false
|
||||
result = "failed to release the username"
|
||||
|
||||
proc getExpirationTime*(username: string, success: var bool): int =
|
||||
let chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
let res = status_ens.expireAt(chainId, username)
|
||||
return fromHex[int](res.result.getStr)
|
||||
|
||||
proc registerUsernameEstimateGas*(username: string, address: string, pubKey: string, success: var bool): int =
|
||||
let
|
||||
chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
txData = transactions.buildTransaction(parseAddress(address), 0.u256)
|
||||
|
||||
try:
|
||||
let resp = status_ens.registerEstimate(chainId, txData, username, pubkey)
|
||||
result = resp.result.getInt
|
||||
success = true
|
||||
except:
|
||||
success = false
|
||||
result = 0
|
||||
|
||||
proc registerUsername*(username, pubKey, address, gas, gasPrice: string, isEIP1559Enabled: bool, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, success: var bool): string =
|
||||
let
|
||||
network = status_settings.getCurrentNetwork().toNetwork()
|
||||
chainId = network.chainId
|
||||
txData = transactions.buildTransaction(
|
||||
parseAddress(address), 0.u256, gas, gasPrice, isEIP1559Enabled, maxPriorityFeePerGas, maxFeePerGas
|
||||
)
|
||||
|
||||
try:
|
||||
let resp = status_ens.register(chainId, txData, password, username, pubkey)
|
||||
result = resp.result.getStr
|
||||
success = true
|
||||
let sntContract = contracts.findErc20Contract(chainId, network.sntSymbol())
|
||||
trackPendingTransaction(result, address, $sntContract.address, PendingTransactionType.RegisterEns, username & domain)
|
||||
except:
|
||||
success = false
|
||||
result = "failed to register the username"
|
||||
|
||||
proc setPubKeyEstimateGas*(username: string, address: string, pubKey: string, success: var bool): int =
|
||||
let
|
||||
chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
txData = transactions.buildTransaction(parseAddress(address), 0.u256)
|
||||
|
||||
try:
|
||||
let resp = status_ens.setPubKeyEstimate(chainId, txData, username, pubkey)
|
||||
result = resp.result.getInt
|
||||
success = true
|
||||
except:
|
||||
success = false
|
||||
result = 0
|
||||
|
||||
proc setPubKey*(username, pubKey, address, gas, gasPrice: string, isEIP1559Enabled: bool, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, success: var bool): string =
|
||||
let
|
||||
chainId = status_settings.getCurrentNetwork().toChainId()
|
||||
txData = transactions.buildTransaction(
|
||||
parseAddress(address), 0.u256, gas, gasPrice, isEIP1559Enabled, maxPriorityFeePerGas, maxFeePerGas
|
||||
)
|
||||
|
||||
try:
|
||||
let resp = status_ens.setPubKey(chainId, txData, password, username, pubkey)
|
||||
result = resp.result.getStr
|
||||
success = true
|
||||
let resolverAddress = resolver(username)
|
||||
trackPendingTransaction(result, $address, resolverAddress, PendingTransactionType.SetPubKey, username)
|
||||
except:
|
||||
success = false
|
||||
result = "failed to set the pubkey"
|
||||
|
||||
proc statusRegistrarAddress*():string =
|
||||
let network = status_settings.getCurrentNetwork().toNetwork()
|
||||
let contract = contracts.findContract(network.chainId, "ens-usernames")
|
||||
if contract != nil:
|
||||
return $contract.address
|
||||
result = ""
|
||||
|
||||
proc validateEnsName*(ens: string, isStatus: bool, usernames: seq[string]): string =
|
||||
var username = ens & (if(isStatus): domain else: "")
|
||||
result = ""
|
||||
if usernames.filter(proc(x: string):bool = x == username).len > 0:
|
||||
result = "already-connected"
|
||||
else:
|
||||
let ownerAddr = owner(username)
|
||||
if ownerAddr == "" and isStatus:
|
||||
result = "available"
|
||||
else:
|
||||
let userPubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let userWallet = status_accounts.getWalletAccounts()[0].address
|
||||
let ens_pubkey = pubkey(ens)
|
||||
if ownerAddr != "":
|
||||
if ens_pubkey == "" and ownerAddr == userWallet:
|
||||
result = "owned" # "Continuing will connect this username with your chat key."
|
||||
elif ens_pubkey == userPubkey:
|
||||
result = "connected"
|
||||
elif ownerAddr == userWallet:
|
||||
result = "connected-different-key" # "Continuing will require a transaction to connect the username with your current chat key.",
|
||||
else:
|
||||
result = "taken"
|
||||
else:
|
||||
result = "taken"
|
||||
proc resourceURL*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chainId, username]
|
||||
result = core.callPrivateRPC("ens_resourceURL", payload)
|
|
@ -1,4 +1,4 @@
|
|||
import json, strutils, strformat
|
||||
import json
|
||||
import ./core, ./response_type
|
||||
|
||||
export response_type
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import stew/byteutils
|
||||
from stew/base32 import nil
|
||||
from stew/base58 import nil
|
||||
import ./statusgo_backend_new/ens as status_ens
|
||||
import chronicles, httpclient, net
|
||||
import strutils
|
||||
import json
|
||||
import semver
|
||||
import constants
|
||||
|
||||
|
||||
type
|
||||
VersionInfo* = object
|
||||
version*: string
|
||||
url*: string
|
||||
|
||||
proc getLatestVersion*(): VersionInfo =
|
||||
let response = status_ens.resourceUrl(chainId=1, username=APP_UPDATES_ENS)
|
||||
let host = response.result{"Host"}.getStr
|
||||
if host == "":
|
||||
raise newException(ValueError, "ENS does not have a content hash")
|
||||
|
||||
let url = "https://" & host & response.result{"Path"}.getStr
|
||||
|
||||
# Read version from folder
|
||||
let secureSSLContext = newContext()
|
||||
let client = newHttpClient(sslContext = secureSSLContext, timeout = CHECK_VERSION_TIMEOUT_MS)
|
||||
result.version = client.getContent(url & "/VERSION").strip()
|
||||
result.url = url
|
||||
|
||||
proc isNewer*(currentVersion, versionToCheck: string): bool =
|
||||
let lastVersion = parseVersion(versionToCheck)
|
||||
let currVersion = parseVersion(currentVersion)
|
||||
result = lastVersion > currVersion
|
Loading…
Reference in New Issue