`account/balance` implementation requirements

I have been working a lot with Rosetta lately. First of all, I really like the overall idea of the project. Thanks for choosing Open Source. I am sure it offers tremendous value for all new platforms.

I am currently implementing the Rosetta Protocol for a cryptocurrency that is a fork of Bitcoin, so I am referring to bitcoin-cli/rpc in the following. I think I already know the answer to my question. I am sure it may help other people in our community if the question pop ups somewhere :grinning:

The bitcoin client does not track addresses because we all know that addresses are just an abstraction above the protocol level. The request of the endpoint account/balance requires an AccountIdentifier which specifies an address.

So you should already be able to guess what question I am about to ask:

Are the Rosetta Implementations supposed to provide a middleware (in that case a database) that keeps track of all addresses/utxos?

AFAIK, there is no other way to determine the balances for an account (except adding ‘watch-only’ accounts using bitcoin-rpc but of course this is very impractical regarding the generic idea of the Rosetta protocol).

So I need to build my own Blockchain Syncer, processing every transaction, is that right?

Thanks in advance! :pray:

For all people who didn’t know:

My question not only affects the /account/balance endpoint, but also the /block endpoint, in which the implementation has to create the one-sided balance operations. This is only possible knowing from which address an input came from.

:wave: @Yoshi!

If you have any suggestions for ways we could improve, we’d love to hear it!



Appreciate you asking this question for the benefit of others :heart:!!

You are, unfortunately, correct that you will need to build some sort of middleware that tracks the UTXOs owned by any address to calculate address balances (I agree that the “watch-only mode” is impractical for this use case). I discovered that the BCHD team implemented a UTXO tracking middleware for their node (which may be of some help depending on what node you are using in your implementation).

Regardless of the underlying accounting model (i.e. UTXO-based in Bitcoin and account-based in Ethereum), the Rosetta tooling runs the same “address reconciliation” process using the address provided in the AccountIdentifier. This “address reconciliation” process confirms that the balance we compute for every address is equal to the balance returned by /account/balance.

You can check out the code for this “address reconciliation” process in rosetta-sdk-go:

Other Resources

I recommend checking out another discussion I had regarding UTXO-based implementations. It contains answers to some other questions you may have while working on your implementation.

1 Like