2

Can I process incoming transfers using only the daemon RPC and my private view key (so without a wallet)? Or how can I decrypt vout from the get_block output JSON?

2

The daemon (monerod) has no wallet functionality, it's for working with the blockchain. To determine incoming transactions for a given wallet (e.g. viewable and spendable using your wallet keys), you would need to scan the blockchain for outputs owned by your wallet and check their spent status.

A full scan (in pseudo code) looks something like follows (ignoring subaddresses):

unspent = [] # array which will hold tuples of (tx, output)
a = hex2bin(v) # my private view key
A = hex2bin(V) # my public view key
b = hex2bin(s) # my private spend key
B = hex2bin(S) # my public spend key

for each block in blockchain:
    for each tx in block:
        R = get_tx_pubkey(tx)
        for each output, i in tx:
            if is_mine(output, R, i) and not is_spent(output, R, i):
                unspent.append((tx, output))

is_mine(out, R, i):
    P = Hs(8aR||i)G + B
    return P == out

is_spent(out, R, i):
    x = Hs(8aR||i) + b
    I = xHp(xG)
    return has_key_image(blockchain, I)

get_tx_pubkey(tx):
    return key from tx.extra

Given the blockchain is hundreds of thousands of blocks each with N transactions, a full scan is pretty intensive.

Also, you cannot perform the above with just the daemon RPC method get_block, because other than the miner tx, get_block will only get you the tx hashes - not the actual tx data. Therefore you'd also need to use get_transactions. And of course, calling these JSON methods repeatedly over the whole blockchain would be very slow.

If you are looking to develop your own wallet implementation, there are the necessary binary methods, which remove the JSON parsing overhead, but really, this is why there is a wallet RPC interface - monero-wallet-rpc. That handles all the lower-level stuff and exposes a useful RPC interface for higher-level wallet functionality.

If you just want to process a single blocks transactions, with only the daemon JSON RPC interface and your wallet keys, you can use get_block (to get each tx hash) and get_transactions (to get the tx pubkey and outputs for each tx). Then you'd need to implement a method like is_mine above to check if you owned a given output and a method like is_spent above to check the spent status (and for has_key_image you could make use of is_key_image_spent).

3
  • Oh, thank you. I will try this way. Can you provide code written by (JS, Python, etc) for one function, maybe for Hs(8aR||i)G + B. Thanks a lot! – intosKai Oct 8 '19 at 12:55
  • For that single line you'll need an ed25519 library for the point multiplications and something that can do a Keecak hash. Look in the various projects at github.com/monero-ecosystem and see which libraries they use. – jtgrassie Oct 8 '19 at 15:12
  • Further explanation. – jtgrassie Oct 28 '19 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.