mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 20:54:20 +01:00
Add expireAt member in ListVtxo RPC (#160)
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var expiryDetailsFlag = cli.BoolFlag{
|
var expiryDetailsFlag = cli.BoolFlag{
|
||||||
Name: "expiry-details",
|
Name: "compute-expiry-details",
|
||||||
Usage: "show cumulative balance by expiry time",
|
Usage: "compute client-side the VTXOs expiry time",
|
||||||
Value: false,
|
Value: false,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ var balanceCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func balanceAction(ctx *cli.Context) error {
|
func balanceAction(ctx *cli.Context) error {
|
||||||
withExpiryDetails := ctx.Bool("expiry-details")
|
computeExpiryDetails := ctx.Bool(expiryDetailsFlag.Name)
|
||||||
|
|
||||||
client, cancel, err := getClientFromState(ctx)
|
client, cancel, err := getClientFromState(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -49,7 +49,7 @@ func balanceAction(ctx *cli.Context) error {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
explorer := NewExplorer(ctx)
|
explorer := NewExplorer(ctx)
|
||||||
balance, amountByExpiration, err := getOffchainBalance(
|
balance, amountByExpiration, err := getOffchainBalance(
|
||||||
ctx, explorer, client, offchainAddr, withExpiryDetails,
|
ctx, explorer, client, offchainAddr, computeExpiryDetails,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chRes <- balanceRes{0, 0, nil, nil, err}
|
chRes <- balanceRes{0, 0, nil, nil, err}
|
||||||
@@ -176,9 +176,7 @@ func balanceAction(ctx *cli.Context) error {
|
|||||||
offchainBalanceJSON["next_expiration"] = fancyTimeExpiration
|
offchainBalanceJSON["next_expiration"] = fancyTimeExpiration
|
||||||
}
|
}
|
||||||
|
|
||||||
if withExpiryDetails {
|
offchainBalanceJSON["details"] = details
|
||||||
offchainBalanceJSON["details"] = details
|
|
||||||
}
|
|
||||||
|
|
||||||
response["offchain_balance"] = offchainBalanceJSON
|
response["offchain_balance"] = offchainBalanceJSON
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type vtxo struct {
|
|||||||
|
|
||||||
func getVtxos(
|
func getVtxos(
|
||||||
ctx *cli.Context, explorer Explorer, client arkv1.ArkServiceClient,
|
ctx *cli.Context, explorer Explorer, client arkv1.ArkServiceClient,
|
||||||
addr string, withExpiration bool,
|
addr string, computeExpiration bool,
|
||||||
) ([]vtxo, error) {
|
) ([]vtxo, error) {
|
||||||
response, err := client.ListVtxos(ctx.Context, &arkv1.ListVtxosRequest{
|
response, err := client.ListVtxos(ctx.Context, &arkv1.ListVtxosRequest{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
@@ -33,15 +33,21 @@ func getVtxos(
|
|||||||
|
|
||||||
vtxos := make([]vtxo, 0, len(response.GetSpendableVtxos()))
|
vtxos := make([]vtxo, 0, len(response.GetSpendableVtxos()))
|
||||||
for _, v := range response.GetSpendableVtxos() {
|
for _, v := range response.GetSpendableVtxos() {
|
||||||
|
var expireAt *time.Time
|
||||||
|
if v.ExpireAt > 0 {
|
||||||
|
t := time.Unix(v.ExpireAt, 0)
|
||||||
|
expireAt = &t
|
||||||
|
}
|
||||||
vtxos = append(vtxos, vtxo{
|
vtxos = append(vtxos, vtxo{
|
||||||
amount: v.Receiver.Amount,
|
amount: v.Receiver.Amount,
|
||||||
txid: v.Outpoint.Txid,
|
txid: v.Outpoint.Txid,
|
||||||
vout: v.Outpoint.Vout,
|
vout: v.Outpoint.Vout,
|
||||||
poolTxid: v.PoolTxid,
|
poolTxid: v.PoolTxid,
|
||||||
|
expireAt: expireAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !withExpiration {
|
if !computeExpiration {
|
||||||
return vtxos, nil
|
return vtxos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,11 +246,11 @@ func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool) ([]vtxo,
|
|||||||
|
|
||||||
func getOffchainBalance(
|
func getOffchainBalance(
|
||||||
ctx *cli.Context, explorer Explorer, client arkv1.ArkServiceClient,
|
ctx *cli.Context, explorer Explorer, client arkv1.ArkServiceClient,
|
||||||
addr string, withExpiration bool,
|
addr string, computeExpiration bool,
|
||||||
) (uint64, map[int64]uint64, error) {
|
) (uint64, map[int64]uint64, error) {
|
||||||
amountByExpiration := make(map[int64]uint64, 0)
|
amountByExpiration := make(map[int64]uint64, 0)
|
||||||
|
|
||||||
vtxos, err := getVtxos(ctx, explorer, client, addr, withExpiration)
|
vtxos, err := getVtxos(ctx, explorer, client, addr, computeExpiration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ func getOffchainBalance(
|
|||||||
for _, vtxo := range vtxos {
|
for _, vtxo := range vtxos {
|
||||||
balance += vtxo.amount
|
balance += vtxo.amount
|
||||||
|
|
||||||
if withExpiration {
|
if vtxo.expireAt != nil {
|
||||||
expiration := vtxo.expireAt.Unix()
|
expiration := vtxo.expireAt.Unix()
|
||||||
|
|
||||||
if _, ok := amountByExpiration[expiration]; !ok {
|
if _, ok := amountByExpiration[expiration]; !ok {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ services:
|
|||||||
- ARK_WALLET_ADDR=oceand:18000
|
- ARK_WALLET_ADDR=oceand:18000
|
||||||
- ARK_ROUND_INTERVAL=10
|
- ARK_ROUND_INTERVAL=10
|
||||||
- ARK_NETWORK=regtest
|
- ARK_NETWORK=regtest
|
||||||
|
- ARK_LOG_LEVEL=5
|
||||||
ports:
|
ports:
|
||||||
- "6000:6000"
|
- "6000:6000"
|
||||||
|
|
||||||
@@ -44,4 +45,4 @@ volumes:
|
|||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
name: nigiri
|
name: nigiri
|
||||||
external: true
|
external: true
|
||||||
|
|||||||
@@ -688,6 +688,10 @@
|
|||||||
},
|
},
|
||||||
"spentBy": {
|
"spentBy": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"expireAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,4 +206,5 @@ message Vtxo {
|
|||||||
bool spent = 3;
|
bool spent = 3;
|
||||||
string pool_txid = 4;
|
string pool_txid = 4;
|
||||||
string spent_by = 5;
|
string spent_by = 5;
|
||||||
|
int64 expire_at = 6;
|
||||||
}
|
}
|
||||||
@@ -1619,6 +1619,7 @@ type Vtxo struct {
|
|||||||
Spent bool `protobuf:"varint,3,opt,name=spent,proto3" json:"spent,omitempty"`
|
Spent bool `protobuf:"varint,3,opt,name=spent,proto3" json:"spent,omitempty"`
|
||||||
PoolTxid string `protobuf:"bytes,4,opt,name=pool_txid,json=poolTxid,proto3" json:"pool_txid,omitempty"`
|
PoolTxid string `protobuf:"bytes,4,opt,name=pool_txid,json=poolTxid,proto3" json:"pool_txid,omitempty"`
|
||||||
SpentBy string `protobuf:"bytes,5,opt,name=spent_by,json=spentBy,proto3" json:"spent_by,omitempty"`
|
SpentBy string `protobuf:"bytes,5,opt,name=spent_by,json=spentBy,proto3" json:"spent_by,omitempty"`
|
||||||
|
ExpireAt int64 `protobuf:"varint,6,opt,name=expire_at,json=expireAt,proto3" json:"expire_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Vtxo) Reset() {
|
func (x *Vtxo) Reset() {
|
||||||
@@ -1688,6 +1689,13 @@ func (x *Vtxo) GetSpentBy() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Vtxo) GetExpireAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ExpireAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_ark_v1_service_proto protoreflect.FileDescriptor
|
var File_ark_v1_service_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_ark_v1_service_proto_rawDesc = []byte{
|
var file_ark_v1_service_proto_rawDesc = []byte{
|
||||||
@@ -1841,7 +1849,7 @@ var file_ark_v1_service_proto_rawDesc = []byte{
|
|||||||
0x04, 0x74, 0x78, 0x69, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x04, 0x74, 0x78, 0x69, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x09, 0x52, 0x02, 0x74, 0x78, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f,
|
0x09, 0x52, 0x02, 0x74, 0x78, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f,
|
||||||
0x74, 0x78, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65,
|
0x74, 0x78, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65,
|
||||||
0x6e, 0x74, 0x54, 0x78, 0x69, 0x64, 0x22, 0xab, 0x01, 0x0a, 0x04, 0x56, 0x74, 0x78, 0x6f, 0x12,
|
0x6e, 0x74, 0x54, 0x78, 0x69, 0x64, 0x22, 0xc8, 0x01, 0x0a, 0x04, 0x56, 0x74, 0x78, 0x6f, 0x12,
|
||||||
0x29, 0x0a, 0x08, 0x6f, 0x75, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x29, 0x0a, 0x08, 0x6f, 0x75, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74,
|
0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74,
|
||||||
0x52, 0x08, 0x6f, 0x75, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x2a, 0x0a, 0x08, 0x72, 0x65,
|
0x52, 0x08, 0x6f, 0x75, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x2a, 0x0a, 0x08, 0x72, 0x65,
|
||||||
@@ -1852,79 +1860,81 @@ var file_ark_v1_service_proto_rawDesc = []byte{
|
|||||||
0x70, 0x6f, 0x6f, 0x6c, 0x5f, 0x74, 0x78, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x70, 0x6f, 0x6f, 0x6c, 0x5f, 0x74, 0x78, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x08, 0x70, 0x6f, 0x6f, 0x6c, 0x54, 0x78, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x70, 0x65,
|
0x08, 0x70, 0x6f, 0x6f, 0x6c, 0x54, 0x78, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x70, 0x65,
|
||||||
0x6e, 0x74, 0x5f, 0x62, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x70, 0x65,
|
0x6e, 0x74, 0x5f, 0x62, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x70, 0x65,
|
||||||
0x6e, 0x74, 0x42, 0x79, 0x32, 0xec, 0x07, 0x0a, 0x0a, 0x41, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76,
|
0x6e, 0x74, 0x42, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x5f, 0x61,
|
||||||
0x69, 0x63, 0x65, 0x12, 0x73, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50,
|
0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41,
|
||||||
0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e,
|
0x74, 0x32, 0xec, 0x07, 0x0a, 0x0a, 0x41, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||||
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52,
|
0x12, 0x73, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d,
|
||||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e,
|
0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67,
|
||||||
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52,
|
0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75,
|
||||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a,
|
0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67,
|
||||||
0x01, 0x2a, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f,
|
0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70,
|
||||||
0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x67, 0x0a, 0x0c, 0x43, 0x6c, 0x61, 0x69,
|
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22,
|
||||||
0x6d, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76,
|
0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x72, 0x65, 0x67,
|
||||||
0x31, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x67, 0x0a, 0x0c, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61,
|
||||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x43,
|
0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x43,
|
||||||
0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x3a, 0x01, 0x2a, 0x22, 0x11,
|
0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6c, 0x61, 0x69,
|
||||||
0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x63, 0x6c, 0x61, 0x69,
|
0x6d, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||||
0x6d, 0x12, 0x73, 0x0a, 0x0f, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79,
|
0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x3a, 0x01, 0x2a, 0x22, 0x11, 0x2f, 0x76, 0x31,
|
||||||
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69,
|
0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x73,
|
||||||
0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71,
|
0x0a, 0x0f, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e,
|
||||||
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69,
|
0x74, 0x12, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c,
|
||||||
0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73,
|
0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a,
|
0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c,
|
||||||
0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x66, 0x69,
|
0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x12, 0x57, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75,
|
0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f,
|
||||||
0x6e, 0x64, 0x12, 0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52,
|
0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c,
|
||||||
0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x72,
|
0x69, 0x7a, 0x65, 0x12, 0x57, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x12,
|
||||||
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73,
|
0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e,
|
||||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f,
|
0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76,
|
||||||
0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x2f, 0x7b, 0x74, 0x78, 0x69, 0x64, 0x7d, 0x12,
|
0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x65, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61,
|
0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f,
|
||||||
0x6d, 0x12, 0x1d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76,
|
0x72, 0x6f, 0x75, 0x6e, 0x64, 0x2f, 0x7b, 0x74, 0x78, 0x69, 0x64, 0x7d, 0x12, 0x65, 0x0a, 0x0e,
|
||||||
0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d,
|
||||||
0x1a, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65,
|
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74,
|
||||||
0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e,
|
||||||
0x22, 0x12, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c, 0x12, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x76,
|
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53,
|
||||||
0x65, 0x6e, 0x74, 0x73, 0x30, 0x01, 0x12, 0x50, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13,
|
0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, 0x82,
|
||||||
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75,
|
0xd3, 0xe4, 0x93, 0x02, 0x0c, 0x12, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74,
|
||||||
0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e,
|
0x73, 0x30, 0x01, 0x12, 0x50, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x61, 0x72,
|
||||||
0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02,
|
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||||
0x17, 0x12, 0x15, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x7b, 0x70, 0x61, 0x79,
|
0x1a, 0x14, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65,
|
||||||
0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5d, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74,
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x12, 0x15,
|
||||||
0x56, 0x74, 0x78, 0x6f, 0x73, 0x12, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c,
|
0x2f, 0x76, 0x31, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x7b, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e,
|
||||||
0x69, 0x73, 0x74, 0x56, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
0x74, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5d, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74, 0x78,
|
||||||
0x19, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74, 0x78,
|
0x6f, 0x73, 0x12, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74,
|
||||||
0x6f, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93,
|
0x56, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x61,
|
||||||
0x02, 0x15, 0x12, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x76, 0x74, 0x78, 0x6f, 0x73, 0x2f, 0x7b, 0x61,
|
0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74, 0x78, 0x6f, 0x73, 0x52,
|
||||||
0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, 0x4c, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x49, 0x6e,
|
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12,
|
||||||
0x66, 0x6f, 0x12, 0x16, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49,
|
0x13, 0x2f, 0x76, 0x31, 0x2f, 0x76, 0x74, 0x78, 0x6f, 0x73, 0x2f, 0x7b, 0x61, 0x64, 0x64, 0x72,
|
||||||
0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x72, 0x6b,
|
0x65, 0x73, 0x73, 0x7d, 0x12, 0x4c, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12,
|
||||||
0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
0x16, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f,
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, 0x76, 0x31,
|
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31,
|
||||||
0x2f, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x52, 0x0a, 0x07, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64,
|
0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||||
0x12, 0x16, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72,
|
0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x6e,
|
||||||
0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76,
|
0x66, 0x6f, 0x12, 0x52, 0x0a, 0x07, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x12, 0x16, 0x2e,
|
||||||
0x31, 0x2e, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x52, 0x65,
|
||||||
0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x76,
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4f,
|
||||||
0x31, 0x2f, 0x6f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x12, 0x78, 0x0a, 0x11, 0x54, 0x72, 0x75,
|
0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16,
|
||||||
0x73, 0x74, 0x65, 0x64, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x20,
|
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x6f,
|
||||||
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x4f,
|
0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x12, 0x78, 0x0a, 0x11, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65,
|
||||||
0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x64, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x20, 0x2e, 0x61, 0x72,
|
||||||
0x1a, 0x21, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65,
|
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x4f, 0x6e, 0x62, 0x6f,
|
||||||
0x64, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e,
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x3a, 0x01, 0x2a, 0x22, 0x13,
|
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x4f, 0x6e,
|
||||||
0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x61, 0x64, 0x64, 0x72,
|
0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||||
0x65, 0x73, 0x73, 0x42, 0x92, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x6b, 0x2e,
|
0x22, 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x3a, 0x01, 0x2a, 0x22, 0x13, 0x2f, 0x76, 0x31,
|
||||||
0x76, 0x31, 0x42, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f,
|
0x2f, 0x6f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
|
||||||
0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61,
|
0x42, 0x92, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x42,
|
||||||
0x72, 0x6b, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x61,
|
0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a,
|
||||||
0x70, 0x69, 0x2d, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
|
0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x6b, 0x2d,
|
||||||
0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x72, 0x6b, 0x76,
|
0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x61, 0x70, 0x69, 0x2d,
|
||||||
0x31, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x41, 0x72, 0x6b, 0x2e, 0x56, 0x31,
|
0x73, 0x70, 0x65, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x65,
|
||||||
0xca, 0x02, 0x06, 0x41, 0x72, 0x6b, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x12, 0x41, 0x72, 0x6b, 0x5c,
|
0x6e, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x72, 0x6b, 0x76, 0x31, 0xa2, 0x02,
|
||||||
0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02,
|
0x03, 0x41, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x41, 0x72, 0x6b, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x06,
|
||||||
0x07, 0x41, 0x72, 0x6b, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x41, 0x72, 0x6b, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x12, 0x41, 0x72, 0x6b, 0x5c, 0x56, 0x31, 0x5c,
|
||||||
|
0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x07, 0x41, 0x72,
|
||||||
|
0x6b, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -110,9 +110,12 @@ func NewService(
|
|||||||
}
|
}
|
||||||
repoManager.RegisterEventsHandler(
|
repoManager.RegisterEventsHandler(
|
||||||
func(round *domain.Round) {
|
func(round *domain.Round) {
|
||||||
go svc.updateVtxoSet(round)
|
|
||||||
go svc.propagateEvents(round)
|
go svc.propagateEvents(round)
|
||||||
go svc.scheduleSweepVtxosForRound(round)
|
go func() {
|
||||||
|
// utxo db must be updated before scheduling the sweep events
|
||||||
|
svc.updateVtxoSet(round)
|
||||||
|
svc.scheduleSweepVtxosForRound(round)
|
||||||
|
}()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ func (s *sweeper) schedule(
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.scheduledTasks[root.Txid] = struct{}{}
|
s.scheduledTasks[root.Txid] = struct{}{}
|
||||||
|
|
||||||
|
if err := s.updateVtxoExpirationTime(congestionTree, expirationTimestamp); err != nil {
|
||||||
|
log.WithError(err).Error("error while updating vtxo expiration time")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,6 +390,30 @@ func (s *sweeper) nodeToSweepInputs(parentBlocktime int64, node tree.Node) (int6
|
|||||||
return expirationTime, sweepInputs, nil
|
return expirationTime, sweepInputs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sweeper) updateVtxoExpirationTime(
|
||||||
|
tree tree.CongestionTree,
|
||||||
|
expirationTime int64,
|
||||||
|
) error {
|
||||||
|
leaves := tree.Leaves()
|
||||||
|
vtxos := make([]domain.VtxoKey, 0)
|
||||||
|
|
||||||
|
for _, leaf := range leaves {
|
||||||
|
pset, err := psetv2.NewPsetFromBase64(leaf.Tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
vtxo, err := extractVtxoOutpoint(pset)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
vtxos = append(vtxos, *vtxo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.repoManager.Vtxos().UpdateExpireAt(context.Background(), vtxos, expirationTime)
|
||||||
|
}
|
||||||
|
|
||||||
func computeSubTrees(congestionTree tree.CongestionTree, inputs []ports.SweepInput) ([]tree.CongestionTree, error) {
|
func computeSubTrees(congestionTree tree.CongestionTree, inputs []ports.SweepInput) ([]tree.CongestionTree, error) {
|
||||||
subTrees := make(map[string]tree.CongestionTree, 0)
|
subTrees := make(map[string]tree.CongestionTree, 0)
|
||||||
|
|
||||||
@@ -498,7 +527,7 @@ func extractSweepLeaf(input psetv2.Input) (sweepLeaf *psetv2.TapLeafScript, life
|
|||||||
return sweepLeaf, lifetime, nil
|
return sweepLeaf, lifetime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// assuming the pset is a leaf in the congestion tree, returns the vtxos outputs
|
// assuming the pset is a leaf in the congestion tree, returns the vtxo outpoint
|
||||||
func extractVtxoOutpoint(pset *psetv2.Pset) (*domain.VtxoKey, error) {
|
func extractVtxoOutpoint(pset *psetv2.Pset) (*domain.VtxoKey, error) {
|
||||||
if len(pset.Outputs) != 2 {
|
if len(pset.Outputs) != 2 {
|
||||||
return nil, fmt.Errorf("invalid leaf pset, expect 2 outputs, got %d", len(pset.Outputs))
|
return nil, fmt.Errorf("invalid leaf pset, expect 2 outputs, got %d", len(pset.Outputs))
|
||||||
|
|||||||
@@ -135,4 +135,5 @@ type Vtxo struct {
|
|||||||
Spent bool
|
Spent bool
|
||||||
Redeemed bool
|
Redeemed bool
|
||||||
Swept bool
|
Swept bool
|
||||||
|
ExpireAt int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ type VtxoRepository interface {
|
|||||||
GetVtxosForRound(ctx context.Context, txid string) ([]Vtxo, error)
|
GetVtxosForRound(ctx context.Context, txid string) ([]Vtxo, error)
|
||||||
SweepVtxos(ctx context.Context, vtxos []VtxoKey) error
|
SweepVtxos(ctx context.Context, vtxos []VtxoKey) error
|
||||||
GetAllVtxos(ctx context.Context, pubkey string) ([]Vtxo, []Vtxo, error)
|
GetAllVtxos(ctx context.Context, pubkey string) ([]Vtxo, []Vtxo, error)
|
||||||
|
UpdateExpireAt(ctx context.Context, vtxos []VtxoKey, expireAt int64) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,24 @@ func (r *vtxoRepository) SweepVtxos(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *vtxoRepository) UpdateExpireAt(ctx context.Context, vtxos []domain.VtxoKey, expireAt int64) error {
|
||||||
|
tx := r.store.Badger().NewTransaction(true)
|
||||||
|
defer tx.Discard()
|
||||||
|
|
||||||
|
for _, vtxo := range vtxos {
|
||||||
|
vtxo, err := r.getVtxo(ctx, vtxo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
vtxo.ExpireAt = expireAt
|
||||||
|
if err := r.store.TxUpdate(tx, vtxo.Hash(), *vtxo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tx.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *vtxoRepository) Close() {
|
func (r *vtxoRepository) Close() {
|
||||||
r.store.Close()
|
r.store.Close()
|
||||||
}
|
}
|
||||||
@@ -211,6 +229,7 @@ func (r *vtxoRepository) redeemVtxo(ctx context.Context, vtxoKey domain.VtxoKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vtxo.Redeemed = true
|
vtxo.Redeemed = true
|
||||||
|
vtxo.ExpireAt = 0
|
||||||
if ctx.Value("tx") != nil {
|
if ctx.Value("tx") != nil {
|
||||||
tx := ctx.Value("tx").(*badger.Txn)
|
tx := ctx.Value("tx").(*badger.Txn)
|
||||||
err = r.store.TxUpdate(tx, vtxoKey.Hash(), *vtxo)
|
err = r.store.TxUpdate(tx, vtxoKey.Hash(), *vtxo)
|
||||||
@@ -247,6 +266,7 @@ func (r *vtxoRepository) sweepVtxo(ctx context.Context, vtxoKey domain.VtxoKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vtxo.Swept = true
|
vtxo.Swept = true
|
||||||
|
vtxo.ExpireAt = 0
|
||||||
if ctx.Value("tx") != nil {
|
if ctx.Value("tx") != nil {
|
||||||
tx := ctx.Value("tx").(*badger.Txn)
|
tx := ctx.Value("tx").(*badger.Txn)
|
||||||
err = r.store.TxUpdate(tx, vtxoKey.Hash(), *vtxo)
|
err = r.store.TxUpdate(tx, vtxoKey.Hash(), *vtxo)
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ func (v vtxoList) toProto(hrp string, aspKey *secp256k1.PublicKey) []*arkv1.Vtxo
|
|||||||
},
|
},
|
||||||
PoolTxid: vv.PoolTx,
|
PoolTxid: vv.PoolTx,
|
||||||
Spent: vv.Spent,
|
Spent: vv.Spent,
|
||||||
|
ExpireAt: vv.ExpireAt,
|
||||||
SpentBy: vv.SpentBy,
|
SpentBy: vv.SpentBy,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user