mirror of
https://github.com/status-im/status-lib.git
synced 2025-02-02 15:43:57 +00:00
refactor: add new module for stickers (#107)
This commit is contained in:
parent
be7a1770a9
commit
ab029aa56f
@ -1,4 +1,4 @@
|
||||
import json, json_serialization, strformat, chronicles
|
||||
import json, json_serialization, strformat, chronicles, nimcrypto
|
||||
import status_go
|
||||
import response_type
|
||||
|
||||
@ -43,3 +43,13 @@ proc signMessage*(rpcParams: string): string =
|
||||
|
||||
proc signTypedData*(data: string, address: string, password: string): string =
|
||||
return $status_go.signTypedData(data, address, password)
|
||||
|
||||
proc sendTransaction*(inputJSON: string, password: string): RpcResponse[JsonNode]
|
||||
{.raises: [RpcException, ValueError, Defect, SerializationError].} =
|
||||
try:
|
||||
var hashed_password = "0x" & $keccak_256.digest(password)
|
||||
let rpcResponseRaw = status_go.sendTransaction(inputJSON, hashed_password)
|
||||
result = Json.decode(rpcResponseRaw, RpcResponse[JsonNode])
|
||||
except RpcException as e:
|
||||
error "error sending tx", inputJSON, exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
@ -36,7 +36,7 @@ proc resolver*(usernameHash: string): string =
|
||||
"data": fmt"{resolver_signature}{userNameHash}"
|
||||
}, "latest"]
|
||||
|
||||
var resolverAddr = eth.call(payload).result.getStr()
|
||||
var resolverAddr = eth.doEthCall(payload).result.getStr()
|
||||
resolverAddr.removePrefix("0x000000000000000000000000")
|
||||
result = "0x" & resolverAddr
|
||||
|
||||
@ -51,7 +51,7 @@ proc contenthash*(ensAddr: string): string =
|
||||
"data": fmt"{contenthash_signature}{ensHash}"
|
||||
}, "latest"]
|
||||
|
||||
let bytesResponse = eth.call(payload).result.getStr()
|
||||
let bytesResponse = eth.doEthCall(payload).result.getStr()
|
||||
if bytesResponse == "0x":
|
||||
return ""
|
||||
|
||||
|
@ -22,5 +22,9 @@ proc getTokenBalance*(tokenAddress: string, accountAddress: string): RpcResponse
|
||||
}, "latest"]
|
||||
return core.callPrivateRPC("eth_call", payload)
|
||||
|
||||
proc call*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return core.callPrivateRPC("eth_call", payload)
|
||||
proc sendTransaction*(transactionData: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
core.sendTransaction(transactionData, password)
|
||||
|
||||
# This is the replacement of the `call` function
|
||||
proc doEthCall*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
core.callPrivateRPC("eth_call", payload)
|
43
status/statusgo_backend_new/stickers.nim
Normal file
43
status/statusgo_backend_new/stickers.nim
Normal file
@ -0,0 +1,43 @@
|
||||
import json
|
||||
import ../statusgo_backend_new/eth as eth
|
||||
|
||||
|
||||
# Retrieves number of sticker packs owned by user
|
||||
# See https://notes.status.im/Q-sQmQbpTOOWCQcYiXtf5g#Read-Sticker-Packs-owned-by-a-user
|
||||
# for more details
|
||||
proc getBalance*(address: string, data: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [{
|
||||
"to": address,
|
||||
"data": data
|
||||
}, "latest"]
|
||||
|
||||
let response = eth.doEthCall(payload)
|
||||
|
||||
if not response.error.isNil:
|
||||
raise newException(RpcException, "Error getting stickers balance: " & response.error.message)
|
||||
|
||||
return response
|
||||
|
||||
proc tokenOfOwnerByIndex*(address: string, data: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [{
|
||||
"to": address,
|
||||
"data": data
|
||||
}, "latest"]
|
||||
|
||||
let response = eth.doEthCall(payload)
|
||||
if not response.error.isNil:
|
||||
raise newException(RpcException, "Error getting owned tokens: " & response.error.message)
|
||||
|
||||
return response
|
||||
|
||||
proc getPackIdFromTokenId*(address: string, data: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [{
|
||||
"to": address,
|
||||
"data": data
|
||||
}, "latest"]
|
||||
|
||||
let response = eth.doEthCall(payload)
|
||||
if not response.error.isNil:
|
||||
raise newException(RpcException, "Error getting pack id from token id: " & response.error.message)
|
||||
|
||||
return response
|
@ -14,4 +14,7 @@ proc getTransfersByAddress*(address: string, toBlock: Uint256, limit: int, loadM
|
||||
limitParsed = "0x" & limit.toHex.stripLeadingZeros
|
||||
|
||||
callPrivateRPC("wallet_getTransfersByAddress", %* [address, toBlockParsed, limitParsed, loadMore])
|
||||
|
||||
|
||||
proc trackPendingTransaction*(hash: string, fromAddress: string, toAddress: string, trxType: PendingTransactionType, data: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [{"hash": hash, "from": fromAddress, "to": toAddress, "type": $trxType, "additionalData": data, "data": "", "value": 0, "timestamp": 0, "gasPrice": 0, "gasLimit": 0}]
|
||||
callPrivateRPC("wallet_storePendingTransaction", payload)
|
Loading…
x
Reference in New Issue
Block a user