mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
Add support for Out Of Round txs (#359)
* [common] rework address encoding * new address encoding * replace offchain address by vtxo output key in DB * merge migrations files into init one * fix txbuilder fixtures * fix transaction events * OOR scheme * fix conflicts * [sdk] OOR * update WASM wrappers * revert renaming * revert API changes * update parser.go * fix vtxosToTxsCovenantless * add settled and spent in Utxo and Transaction * Fixes (#5) * Revert unneeded changes and rename claim to settle * Revert changes to wasm and rename claim to settle --------- Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/ark-network/ark/common"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/client"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/types"
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
@@ -23,10 +24,14 @@ import (
|
||||
)
|
||||
|
||||
func CoinSelect(
|
||||
vtxos []client.DescriptorVtxo, amount, dust uint64, sortByExpirationTime bool,
|
||||
) ([]client.DescriptorVtxo, uint64, error) {
|
||||
selected := make([]client.DescriptorVtxo, 0)
|
||||
notSelected := make([]client.DescriptorVtxo, 0)
|
||||
boardingUtxos []types.Utxo,
|
||||
vtxos []client.DescriptorVtxo,
|
||||
amount,
|
||||
dust uint64,
|
||||
sortByExpirationTime bool,
|
||||
) ([]types.Utxo, []client.DescriptorVtxo, uint64, error) {
|
||||
selected, notSelected := make([]client.DescriptorVtxo, 0), make([]client.DescriptorVtxo, 0)
|
||||
selectedBoarding, notSelectedBoarding := make([]types.Utxo, 0), make([]types.Utxo, 0)
|
||||
selectedAmount := uint64(0)
|
||||
|
||||
if sortByExpirationTime {
|
||||
@@ -38,6 +43,20 @@ func CoinSelect(
|
||||
|
||||
return vtxos[i].ExpiresAt.Before(*vtxos[j].ExpiresAt)
|
||||
})
|
||||
|
||||
sort.SliceStable(boardingUtxos, func(i, j int) bool {
|
||||
return boardingUtxos[i].SpendableAt.Before(boardingUtxos[j].SpendableAt)
|
||||
})
|
||||
}
|
||||
|
||||
for _, boardingUtxo := range boardingUtxos {
|
||||
if selectedAmount >= amount {
|
||||
notSelectedBoarding = append(notSelectedBoarding, boardingUtxo)
|
||||
break
|
||||
}
|
||||
|
||||
selectedBoarding = append(selectedBoarding, boardingUtxo)
|
||||
selectedAmount += boardingUtxo.Amount
|
||||
}
|
||||
|
||||
for _, vtxo := range vtxos {
|
||||
@@ -51,7 +70,7 @@ func CoinSelect(
|
||||
}
|
||||
|
||||
if selectedAmount < amount {
|
||||
return nil, 0, fmt.Errorf("not enough funds to cover amount %d", amount)
|
||||
return nil, nil, 0, fmt.Errorf("not enough funds to cover amount %d", amount)
|
||||
}
|
||||
|
||||
change := selectedAmount - amount
|
||||
@@ -60,10 +79,13 @@ func CoinSelect(
|
||||
if len(notSelected) > 0 {
|
||||
selected = append(selected, notSelected[0])
|
||||
change += notSelected[0].Amount
|
||||
} else if len(notSelectedBoarding) > 0 {
|
||||
selectedBoarding = append(selectedBoarding, notSelectedBoarding[0])
|
||||
change += notSelectedBoarding[0].Amount
|
||||
}
|
||||
}
|
||||
|
||||
return selected, change, nil
|
||||
return selectedBoarding, selected, change, nil
|
||||
}
|
||||
|
||||
func ParseLiquidAddress(addr string) (
|
||||
|
||||
Reference in New Issue
Block a user