Skip to content

Commit

Permalink
Port the Transactions/Consensus/Merit/Network RPC modules.
Browse files Browse the repository at this point in the history
Without the matching macro, this is mostly meaningless. Updates the docs 
accordingly.

Notably removed is the ability to broadcast DataDiffs/SendDiffs. This is 
due to the fact they're ordered and sequential, and at the same time, 
the protocol doesn't alloow requesting specific Elems. This means 
broadcasting Elem 5 will forever be doomed if Elem 4 didn't propagate.
  • Loading branch information
kayabaNerve committed Jan 3, 2021
1 parent 6382f30 commit 17152a3
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 344 deletions.
16 changes: 8 additions & 8 deletions docs/RPC/Merit.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ The result is an object, as follows:

- `aggregate` (string)

### `getNickname`
### `getPublicKey`

`getNickname` replies with a Merit Holder's nickname.
`getPublicKey` replies with the specified Merit Holder's BLS Public Key.

Arguments:
- `key` (string): Merit Holder's BLS Public Key.
- `nick` (int)

The result is an int of the nickname.
The result is an string of the BLS Public Key.

### `getPublicKey`
### `getNickname`

`getPublicKey` replies with the specified Merit Holder's BLS Public Key.
`getNickname` replies with a Merit Holder's nickname.

Arguments:
- `nick` (int)
- `key` (string): Merit Holder's BLS Public Key.

The result is an string of the BLS Public Key.
The result is an int of the nickname.

### `getTotalMerit`

Expand Down
5 changes: 1 addition & 4 deletions docs/RPC/Network.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ The result is a bool of true.
`broadcast` broadcasts existing local data. Because it's already been processed locally, its presumably already been broadcasted around the network. This is meant to cover for any local networking issues/propagation shortcomings that may occur.

Arguments:
- `transaction` (string): Optional; hash of the Transaction to broadcast.
- `transaction` (string): Optional; hash of the Transaction to broadcast. When the Transaction is a Mint, this does nothing.
- `block` (string): Optional; hash of the Block to broadcast.
- `element` (object): Optional
- `holder` (int)
- `nonce` (int)

The result is a bool of true.
14 changes: 7 additions & 7 deletions docs/RPC/Transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ The result is an object, as follows:
- `inputs` (array of objects, each as follows)
- `hash` (string)

When (`descendant` == "claim") or (`descendant` == "send"):
When (`descendant` == "Claim") or (`descendant` == "Send"):
- `nonce` (int)

- `outputs` (array of objects, each as follows)
- `amount` (string)

When `descendant` == "mint":
When `descendant` == "Mint":
- `key` (int): Miner nickname.

When `descendant` == "claim" or `descendant` == "send":
When `descendant` == "Claim" or `descendant` == "Send":
- `key` (string): Ed25519 Public Key.

- `hash` (string)

When `descendant` == "claim":
When `descendant` == "Claim":
- `signature` (string)

When `descendant` == "send":
When `descendant` == "Send":
- `signature` (string)
- `proof` (int)
- `argon` (string)

When `descendant` == "data":
When `descendant` == "Data":
- `data` (string)
- `signature` (string)
- `proof` (int)
Expand Down Expand Up @@ -66,7 +66,7 @@ The result is a string of the balance.
`publishTransaction` accepts a serialized Transaction, attempts to add it to the local Transactions DAG, and on success, broadcasts it to the network.

Arguments:
- `type` (string): "claim", "send", or "data".
- `type` (string): "Claim", "Send", or "Data".
- `transaction` (string): Serialized Transaction.

The result is a bool of if the transaction was successfully added. This will return true if the transaction is valid yet already exists, though it will NOT be broadcasted again in that case.
53 changes: 18 additions & 35 deletions src/Interfaces/RPC/Modules/ConsensusModule.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,25 @@ proc module*(
): RPCFunctions {.forceCheck: [].} =
try:
newRPCFunctions:
"getSendDifficulty" = proc (
res: JSONNode,
params: JSONNode
proc getSendDifficulty(
holder: Option[uint16] = none(uint16)
): int {.forceCheck: [].} =
if holder.isSome:
result = functions.consensus.getSendDifficultyOfHolder(holder.unsafeGet())
else:
result = functions.consensus.getSendDifficulty()

proc getDataDifficulty(
holder: Option[uint16] = none(uint16)
): int {.forceCheck: [].} =
if holder.isSome:
result = functions.consensus.getDataDifficultyOfHolder(holder.unsafeGet())
else:
result = functions.consensus.getDataDifficulty()

proc getStatus(
hash: Hash[256]
) {.forceCheck: [].} =
res["result"] = % functions.consensus.getSendDifficulty()

"getDataDifficulty" = proc (
res: JSONNode,
params: JSONNode
) {.forceCheck: [].} =
res["result"] = % functions.consensus.getDataDifficulty()

"getStatus" = proc (
res: JSONNode,
params: JSONNode
) {.forceCheck: [
ParamError,
JSONRPCError
].} =
#Verify the parameters.
if (
(params.len != 1) or
(params[0].kind != JString)
):
raise newException(ParamError, "")

#Extract the parameter.
var hash: Hash[256]
try:
var strHash: string = parseHexStr(params[0].getStr())
if strHash.len != 32:
raise newJSONRPCError(-3, "Invalid hash")
hash = strHash.toHash[:256]()
except ValueError:
raise newJSONRPCError(-3, "Invalid hash")

#Get the Status.
var status: TransactionStatus
try:
Expand Down
Loading

0 comments on commit 17152a3

Please sign in to comment.