-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Is this a BUG REPORT or FEATURE REQUEST? (choose one):
Feature Request
Tendermint version (use tendermint version or git rev-parse --verify HEAD if installed from source):
Last tested on rpc bugfix branch
0.17.0-34c800c1
(but also with 0.16.1 and 0.17.1)
ABCI app (name for built-in, URL for self-written if it's publicly available):
https://github.com/confio/weave - mycoind
Use Case
I have a wallet and want to be notified of changes, so I can subscribe to all tx that affect the balance.
Ideally, I would do something like tm.event = 'Tx' AND wallet='<my hex address>'. However, this would require the transaction to create two events wallet=<sender hex address> and wallet=<recipient hex address>. This is currently not supported.
A previous release of cosmos-sdk:basecoind resolved this by using one tag for sender and one for recipient. This is a temporary work-around, but brings up two issues. First, because queries do not support OR, we need to make two separate subscriptions (sender=<my hex address> and recipient=<my hex address>). These both will make separate callbacks, and when I send some cash to myself it will show up twice. (This is a bit annoying, ask @faboweb and his desire for the txhash on subscriptions to detect duplicates, now fixed #1367).
A bigger issue is multi-account sends. basecoind is set up to allow many input accounts and many output accounts, similar to the bitcoin model, which allows for secure swaps in one tx with multiple signatures. However, if there ever was a transaction with two senders, the above work-around wouldn't work and it is impossible to subscribe to all multi-output transactions that affect your account.
Also, please note that the /search_tx functionality currently supports the same key showing up on a given tx multiple times with different values, and searching for any of them will match the tx. Making this change will maintain consistency between the search and subscribe interfaces.
Proposed Changes
Look at https://github.com/tendermint/tendermint/blob/develop/types/event_bus.go#L88-L120
func (b *EventBus) PublishEventTx(event EventDataTx) error builds up a map[string]interface{} of all the tags. The contents are currently either string or int64 (only for height). (Actually also an unmatchable []byte but that should be fixed in another issue).
I would propose another case []string, which is used on all event.Result.Tags. When matching, the subscription will match if the query matches any of the strings in the slice. We still require multiple kvpairs and do not complicate that interface, we only aggragate them when building the map in PublishEventTx.
Dependencies
The fact that subscribing to delivertx tags works at all depends upon locally applying the patch that @melekes identified as part of #1369 (comment)
I would be fine writing and submitting a PR once a proper solution to that bug is merged into develop, and there is agreement that this feature is desired.