Closed bordalix closed 2 years ago
Here is the plan:
This means that spend
and send
must know which utxos where selected for the transaction and lock them.
My idea is to use this to store locked utxos:
{
...state,
unspentsAndTransactions: {
...state.unspentsAndTransactions,
[accountID]: {
...state.unspentsAndTransactions[accountID],
[network]: {
...state.unspentsAndTransactions[accountID][network],
utxosMap: {
...state.unspentsAndTransactions[accountID][network].utxosMap,
},
lockedUtxos: {
...state.unspentsAndTransactions[accountID][network].lockedUtxos,
[toStringOutpoint(utxo)]: 'locked',
},
},
},
},
}
@louisinger @tiero any thoughts?
This means that
spend
andsend
must know which utxos where selected for the transaction and lock them.
We should use the tdex-app logic: it writes a custom coin selector from redux's Dispatch function --> each time the selector is selecting a coin, a LOCK_UTXO action is dispatched.
Note that usually, the locked unspents should be unlocked after a certain amount of time (1 min for instance): it lets to ensure we get back the utxos if the transaction is never broadcasted for instance.
{ ...state, unspentsAndTransactions: { ...state.unspentsAndTransactions, [accountID]: { ...state.unspentsAndTransactions[accountID], [network]: { ...state.unspentsAndTransactions[accountID][network], utxosMap: { ...state.unspentsAndTransactions[accountID][network].utxosMap, }, lockedUtxos: { ...state.unspentsAndTransactions[accountID][network].lockedUtxos, [toStringOutpoint(utxo)]: 'locked', }, }, }, }, }
I don't think we need to store a locker for each network, 1 lockedUtxos
cleaned if the network changes should be enough?
We should use the tdex-app logic: it writes a custom coin selector from redux's Dispatch function --> each time the selector is selecting a coin, a LOCK_UTXO action is dispatched.
Nice, thanks for the tip.
Note that usually, the locked unspents should be unlocked after a certain amount of time (1 min for instance): it lets to ensure we get back the utxos if the transaction is never broadcasted for instance.
So they should store the timestamp when they are locked, and every minute an alarm should clean up all locked utxos with timestamp less then X. It works.
I don't think we need to store a locker for each network, 1
lockedUtxos
cleaned if the network changes should be enough?
Yes, it makes sense.
After used in a transaction, utxos should be locked to prevent: