From 54c6d0c22dc7cafe6c9b12c480ebfebfc086b8c7 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 20 Jan 2020 12:17:22 -0600 Subject: [PATCH] Update the RPC with Miner Wallet management. --- docs/Development/TODO.md | 3 --- docs/RPC/Current/Personal.md | 6 +++++- docs/RPC/Eventual/Personal.md | 13 ++++++++++++- src/Interfaces/RPC/Modules/PersonalModule.nim | 12 ++++++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/Development/TODO.md b/docs/Development/TODO.md index dd738df89..ee5745005 100644 --- a/docs/Development/TODO.md +++ b/docs/Development/TODO.md @@ -20,9 +20,6 @@ Consensus: - GasPrice. -- Same Nonce Merit Removals. -- Verify Competing Merit Removals. - Interfaces: - Add missing methods detailed under the Eventual docs. diff --git a/docs/RPC/Current/Personal.md b/docs/RPC/Current/Personal.md index be5ac7934..32310d068 100644 --- a/docs/RPC/Current/Personal.md +++ b/docs/RPC/Current/Personal.md @@ -1,8 +1,12 @@ # Personal Module +### `getMiner` + +`getMiner` replies with the BLS Private Key of the current Miner Wallet. It takes in zero arguments and the result is a string of the private key. + ### `setMnemonic` -`setMnemonic` creates a new Wallet using the passed in Mnemonic and password, and set the Node's Wallet to it. It takes in two arguments: +`setMnemonic` creates a new Wallet using the passed in Mnemonic and password and sets the Node's Wallet to it. It takes in two arguments: - Mnemonic (string): Optional; creates a new Mnemonic if omitted. - Password (string): Optional; defaults to "" if omitted, as according to the BIP 39 spec. diff --git a/docs/RPC/Eventual/Personal.md b/docs/RPC/Eventual/Personal.md index 8590cf51c..7ef05108c 100644 --- a/docs/RPC/Eventual/Personal.md +++ b/docs/RPC/Eventual/Personal.md @@ -1,8 +1,19 @@ # Personal Module +### `setMiner` + +`setMiner` creates a new Miner Wallet using the passed in BLS Private Key and sets the Node's Miner Wallet to it. It takes in one argument: +- Private Key (string): Optional; creates a new Private Key if omitted. + +The result is a bool of true. + +### `getMiner` + +`getMiner` replies with the BLS Private Key of the current Miner Wallet. It takes in zero arguments and the result is a string of the private key. + ### `setMnemonic` -`setMnemonic` creates a new Wallet using the passed in Mnemonic and password, and set the Node's Wallet to it. It takes in two arguments: +`setMnemonic` creates a new Wallet using the passed in Mnemonic and password and sets the Node's Wallet to it. It takes in two arguments: - Mnemonic (string): Optional; creates a new Mnemonic if omitted. - Password (string): Optional; defaults to "" if omitted, as according to the BIP 39 spec. diff --git a/src/Interfaces/RPC/Modules/PersonalModule.nim b/src/Interfaces/RPC/Modules/PersonalModule.nim index 41ef206fa..d6bbc3dd8 100644 --- a/src/Interfaces/RPC/Modules/PersonalModule.nim +++ b/src/Interfaces/RPC/Modules/PersonalModule.nim @@ -7,8 +7,9 @@ import ../../../lib/Util #Hash lib. import ../../../lib/Hash -#Wallet lib. +#Wallet libs. import ../../../Wallet/Wallet +import ../../../Wallet/MinerWallet #Transactions lib. import ../../../Database/Transactions/Transactions @@ -25,6 +26,13 @@ proc module*( ): RPCFunctions {.forceCheck: [].} = try: newRPCFunctions: + #Get the Node's MinerWallet's private key. + "getMiner" = proc ( + res: JSONNode, + params: JSONNode + ) {.forceCheck: [].} = + res["result"] = % $functions.personal.getMinerWallet().privateKey + #Set the Node's Wallet's Mnemonic. "setMnemonic" = proc ( res: JSONNode, @@ -143,7 +151,7 @@ proc module*( try: res["result"] = % $functions.personal.data(params[0].getStr()) except ValueError: - raise newJSONRPCError(-3, "Invalid data length") + raise newJSONRPCError(-3, "Invalid data length or missing datas") except DataExists: raise newJSONRPCError(0, "Data exists")