Fix more return values + minor improvements

This commit is contained in:
kdeme 2019-04-26 13:40:28 +02:00
parent 7ab84641d6
commit 9de9741e3c
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
2 changed files with 11 additions and 11 deletions

View File

@ -8,8 +8,6 @@ from byteutils import hexToSeqByte, hexToByteArray
# Whisper RPC implemented mostly as in # Whisper RPC implemented mostly as in
# https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API # https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API
# TODO: rpc calls -> check all return values and matching documentation
type type
WhisperKeys* = ref object WhisperKeys* = ref object
asymKeys*: Table[string, KeyPair] asymKeys*: Table[string, KeyPair]
@ -47,6 +45,8 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
## ##
## Returns true on success and an error on failure. ## Returns true on success and an error on failure.
result = node.setMaxMessageSize(size.uint32) result = node.setMaxMessageSize(size.uint32)
if not result:
raise newException(ValueError, "Invalid size")
rpcsrv.rpc("shh_setMinPoW") do(pow: float) -> bool: rpcsrv.rpc("shh_setMinPoW") do(pow: float) -> bool:
## Sets the minimal PoW required by this node. ## Sets the minimal PoW required by this node.
@ -77,6 +77,8 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
# could also accept only the pubkey (like geth)? # could also accept only the pubkey (like geth)?
let peerNode = newNode(enode) let peerNode = newNode(enode)
result = node.setPeerTrusted(peerNode.id) result = node.setPeerTrusted(peerNode.id)
if not result:
raise newException(ValueError, "Not a peer")
rpcsrv.rpc("shh_newKeyPair") do() -> Identifier: rpcsrv.rpc("shh_newKeyPair") do() -> Identifier:
## Generates a new public and private key pair for message decryption and ## Generates a new public and private key pair for message decryption and
@ -290,10 +292,8 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
for msg in messages: for msg in messages:
var filterMsg: WhisperFilterMessage var filterMsg: WhisperFilterMessage
if msg.decoded.src.isSome(): filterMsg.sig = msg.decoded.src
filterMsg.sig = some(msg.decoded.src.get()) filterMsg.recipientPublicKey = msg.dst
if msg.dst.isSome():
filterMsg.recipientPublicKey = some(msg.dst.get())
filterMsg.ttl = msg.ttl filterMsg.ttl = msg.ttl
filterMsg.topic = msg.topic filterMsg.topic = msg.topic
filterMsg.timestamp = msg.timestamp filterMsg.timestamp = msg.timestamp
@ -320,15 +320,12 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
validateOptions(message.pubKey, message.symKeyID, message.topic) validateOptions(message.pubKey, message.symKeyID, message.topic)
var var
pubKey: Option[PublicKey]
sigPrivKey: Option[PrivateKey] sigPrivKey: Option[PrivateKey]
symKey: Option[SymKey] symKey: Option[SymKey]
topic: whisper_protocol.Topic topic: whisper_protocol.Topic
padding: Option[Bytes] padding: Option[Bytes]
targetPeer: Option[NodeId] targetPeer: Option[NodeId]
pubKey = message.pubKey
if message.sig.isSome(): if message.sig.isSome():
sigPrivKey = some(keys.asymKeys[message.sig.get().string].seckey) sigPrivKey = some(keys.asymKeys[message.sig.get().string].seckey)
@ -345,7 +342,7 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
if message.targetPeer.isSome(): if message.targetPeer.isSome():
targetPeer = some(newNode(message.targetPeer.get()).id) targetPeer = some(newNode(message.targetPeer.get()).id)
result = node.postMessage(pubKey, result = node.postMessage(message.pubKey,
symKey, symKey,
sigPrivKey, sigPrivKey,
ttl = message.ttl.uint32, ttl = message.ttl.uint32,
@ -355,3 +352,5 @@ proc setupWhisperRPC*(node: EthereumNode, keys: WhisperKeys, rpcsrv: RpcServer)
powTime = message.powTime, powTime = message.powTime,
powTarget = message.powTarget, powTarget = message.powTarget,
targetPeer = targetPeer) targetPeer = targetPeer)
if not result:
raise newException(ValueError, "Message could not be posted")

View File

@ -38,7 +38,8 @@ proc doTests =
check waitFor(client.shh_setMaxMessageSize(testValue)) == true check waitFor(client.shh_setMaxMessageSize(testValue)) == true
var info = waitFor client.shh_info() var info = waitFor client.shh_info()
check info.maxMessageSize == testValue check info.maxMessageSize == testValue
check waitFor(client.shh_setMaxMessageSize(defaultMaxMsgSize + 1)) == false expect Exception:
discard waitFor(client.shh_setMaxMessageSize(defaultMaxMsgSize + 1))
info = waitFor client.shh_info() info = waitFor client.shh_info()
check info.maxMessageSize == testValue check info.maxMessageSize == testValue
test "shh_setMinPoW": test "shh_setMinPoW":