From b2a08955add51ec9a1418286062c1196579ed569 Mon Sep 17 00:00:00 2001 From: altafan <18440657+altafan@users.noreply.github.com> Date: Wed, 28 Feb 2024 19:37:11 +0100 Subject: [PATCH] Return unconfirmed utxos --- .../protobuf/gen/go/ocean/v1/account.pb.go | 227 +++++++++--------- api-spec/protobuf/ocean/v1/account.proto | 2 + internal/core/application/account_service.go | 23 +- .../core/application/transaction_service.go | 6 +- internal/core/application/types.go | 5 +- internal/core/domain/utxo_repository.go | 11 +- .../storage/db/badger/utxo_repository.go | 46 ++-- .../storage/db/inmemory/utxo_repository.go | 12 +- .../storage/db/postgres/utxo_repository.go | 39 ++- .../storage/db/test/utxo_repository_test.go | 22 +- internal/interfaces/grpc/handler/account.go | 5 + 11 files changed, 200 insertions(+), 198 deletions(-) diff --git a/api-spec/protobuf/gen/go/ocean/v1/account.pb.go b/api-spec/protobuf/gen/go/ocean/v1/account.pb.go index dc81e7be..a900c590 100644 --- a/api-spec/protobuf/gen/go/ocean/v1/account.pb.go +++ b/api-spec/protobuf/gen/go/ocean/v1/account.pb.go @@ -1011,6 +1011,8 @@ type ListUtxosResponse struct { SpendableUtxos *Utxos `protobuf:"bytes,1,opt,name=spendable_utxos,json=spendableUtxos,proto3" json:"spendable_utxos,omitempty"` // List of currently locked utxos. LockedUtxos *Utxos `protobuf:"bytes,2,opt,name=locked_utxos,json=lockedUtxos,proto3" json:"locked_utxos,omitempty"` + // List of unconfirmed utxos. + UnconfirmedUtxos *Utxos `protobuf:"bytes,3,opt,name=unconfirmed_utxos,json=unconfirmedUtxos,proto3" json:"unconfirmed_utxos,omitempty"` } func (x *ListUtxosResponse) Reset() { @@ -1059,6 +1061,13 @@ func (x *ListUtxosResponse) GetLockedUtxos() *Utxos { return nil } +func (x *ListUtxosResponse) GetUnconfirmedUtxos() *Utxos { + if x != nil { + return x.UnconfirmedUtxos + } + return nil +} + type DeleteAccountRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1248,7 +1257,7 @@ var file_ocean_v1_account_proto_rawDesc = []byte{ 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x65, 0x73, 0x22, 0x81, 0x01, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, + 0x65, 0x73, 0x22, 0xbf, 0x01, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0f, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x75, 0x74, 0x78, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x74, 0x78, @@ -1256,86 +1265,89 @@ var file_ocean_v1_account_proto_rawDesc = []byte{ 0x6f, 0x73, 0x12, 0x32, 0x0a, 0x0c, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x75, 0x74, 0x78, 0x6f, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x65, - 0x64, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x22, 0x39, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, - 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x61, 0x6d, - 0x65, 0x22, 0x17, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xe4, 0x07, 0x0a, 0x0e, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, - 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x49, - 0x50, 0x34, 0x34, 0x12, 0x23, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x64, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x12, 0x3c, 0x0a, 0x11, 0x75, 0x6e, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x72, 0x6d, 0x65, 0x64, 0x5f, 0x75, 0x74, 0x78, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x74, 0x78, + 0x6f, 0x73, 0x52, 0x10, 0x75, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65, 0x64, 0x55, + 0x74, 0x78, 0x6f, 0x73, 0x22, 0x39, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, + 0x17, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xe4, 0x07, 0x0a, 0x0e, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x49, 0x50, 0x34, - 0x34, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, - 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x42, 0x49, 0x50, 0x34, 0x34, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, - 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, - 0x75, 0x6c, 0x74, 0x69, 0x53, 0x69, 0x67, 0x12, 0x26, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, - 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x53, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x27, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x53, 0x69, 0x67, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x62, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x12, - 0x24, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, - 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, - 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, - 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x12, - 0x20, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x21, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x12, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x6f, 0x63, 0x65, - 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x24, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x20, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, + 0x34, 0x12, 0x23, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x49, 0x50, 0x34, 0x34, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, + 0x49, 0x50, 0x34, 0x34, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x15, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x75, 0x6c, + 0x74, 0x69, 0x53, 0x69, 0x67, 0x12, 0x26, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x75, + 0x6c, 0x74, 0x69, 0x53, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, + 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x53, 0x69, 0x67, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x62, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x12, 0x24, 0x2e, + 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x75, 0x73, 0x74, + 0x6f, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, 0x53, 0x65, + 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x12, 0x20, 0x2e, + 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x21, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x12, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x65, + 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, + 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x20, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x6f, 0x63, 0x65, - 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x41, 0x64, 0x64, 0x72, - 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, - 0x15, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, 0x64, - 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x26, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, - 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x1e, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x12, 0x18, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, - 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, - 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, - 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x12, 0x1a, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, - 0x73, 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x50, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x12, 0x1e, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x42, 0xa5, 0x01, 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, - 0x76, 0x31, 0x42, 0x0c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, - 0x75, 0x6c, 0x70, 0x65, 0x6d, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2f, 0x6f, 0x63, - 0x65, 0x61, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2d, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2f, - 0x76, 0x31, 0x3b, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x58, 0x58, - 0xaa, 0x02, 0x08, 0x4f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x08, 0x4f, 0x63, - 0x65, 0x61, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x14, 0x4f, 0x63, 0x65, 0x61, 0x6e, 0x5c, 0x56, - 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x09, - 0x4f, 0x63, 0x65, 0x61, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x73, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x15, 0x44, + 0x65, 0x72, 0x69, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x65, 0x73, 0x12, 0x26, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, 0x64, 0x72, + 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6f, + 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x72, 0x69, 0x76, 0x65, 0x43, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x1e, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x42, 0x61, 0x6c, 0x61, 0x6e, + 0x63, 0x65, 0x12, 0x18, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x6f, + 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x55, + 0x74, 0x78, 0x6f, 0x73, 0x12, 0x1a, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1b, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x55, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, + 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1e, + 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0xa5, 0x01, 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x76, 0x31, + 0x42, 0x0c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, + 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x75, 0x6c, + 0x70, 0x65, 0x6d, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2f, 0x6f, 0x63, 0x65, 0x61, + 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2d, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2f, 0x76, 0x31, + 0x3b, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x58, 0x58, 0xaa, 0x02, + 0x08, 0x4f, 0x63, 0x65, 0x61, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x08, 0x4f, 0x63, 0x65, 0x61, + 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x14, 0x4f, 0x63, 0x65, 0x61, 0x6e, 0x5c, 0x56, 0x31, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x09, 0x4f, 0x63, + 0x65, 0x61, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1389,34 +1401,35 @@ var file_ocean_v1_account_proto_depIdxs = []int32{ 22, // 5: ocean.v1.BalanceResponse.balance:type_name -> ocean.v1.BalanceResponse.BalanceEntry 25, // 6: ocean.v1.ListUtxosResponse.spendable_utxos:type_name -> ocean.v1.Utxos 25, // 7: ocean.v1.ListUtxosResponse.locked_utxos:type_name -> ocean.v1.Utxos - 26, // 8: ocean.v1.BalanceResponse.BalanceEntry.value:type_name -> ocean.v1.BalanceInfo - 0, // 9: ocean.v1.AccountService.CreateAccountBIP44:input_type -> ocean.v1.CreateAccountBIP44Request - 2, // 10: ocean.v1.AccountService.CreateAccountMultiSig:input_type -> ocean.v1.CreateAccountMultiSigRequest - 4, // 11: ocean.v1.AccountService.CreateAccountCustom:input_type -> ocean.v1.CreateAccountCustomRequest - 6, // 12: ocean.v1.AccountService.SetAccountLabel:input_type -> ocean.v1.SetAccountLabelRequest - 8, // 13: ocean.v1.AccountService.SetAccountTemplate:input_type -> ocean.v1.SetAccountTemplateRequest - 10, // 14: ocean.v1.AccountService.DeriveAddresses:input_type -> ocean.v1.DeriveAddressesRequest - 12, // 15: ocean.v1.AccountService.DeriveChangeAddresses:input_type -> ocean.v1.DeriveChangeAddressesRequest - 14, // 16: ocean.v1.AccountService.ListAddresses:input_type -> ocean.v1.ListAddressesRequest - 16, // 17: ocean.v1.AccountService.Balance:input_type -> ocean.v1.BalanceRequest - 18, // 18: ocean.v1.AccountService.ListUtxos:input_type -> ocean.v1.ListUtxosRequest - 20, // 19: ocean.v1.AccountService.DeleteAccount:input_type -> ocean.v1.DeleteAccountRequest - 1, // 20: ocean.v1.AccountService.CreateAccountBIP44:output_type -> ocean.v1.CreateAccountBIP44Response - 3, // 21: ocean.v1.AccountService.CreateAccountMultiSig:output_type -> ocean.v1.CreateAccountMultiSigResponse - 5, // 22: ocean.v1.AccountService.CreateAccountCustom:output_type -> ocean.v1.CreateAccountCustomResponse - 7, // 23: ocean.v1.AccountService.SetAccountLabel:output_type -> ocean.v1.SetAccountLabelResponse - 9, // 24: ocean.v1.AccountService.SetAccountTemplate:output_type -> ocean.v1.SetAccountTemplateResponse - 11, // 25: ocean.v1.AccountService.DeriveAddresses:output_type -> ocean.v1.DeriveAddressesResponse - 13, // 26: ocean.v1.AccountService.DeriveChangeAddresses:output_type -> ocean.v1.DeriveChangeAddressesResponse - 15, // 27: ocean.v1.AccountService.ListAddresses:output_type -> ocean.v1.ListAddressesResponse - 17, // 28: ocean.v1.AccountService.Balance:output_type -> ocean.v1.BalanceResponse - 19, // 29: ocean.v1.AccountService.ListUtxos:output_type -> ocean.v1.ListUtxosResponse - 21, // 30: ocean.v1.AccountService.DeleteAccount:output_type -> ocean.v1.DeleteAccountResponse - 20, // [20:31] is the sub-list for method output_type - 9, // [9:20] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 25, // 8: ocean.v1.ListUtxosResponse.unconfirmed_utxos:type_name -> ocean.v1.Utxos + 26, // 9: ocean.v1.BalanceResponse.BalanceEntry.value:type_name -> ocean.v1.BalanceInfo + 0, // 10: ocean.v1.AccountService.CreateAccountBIP44:input_type -> ocean.v1.CreateAccountBIP44Request + 2, // 11: ocean.v1.AccountService.CreateAccountMultiSig:input_type -> ocean.v1.CreateAccountMultiSigRequest + 4, // 12: ocean.v1.AccountService.CreateAccountCustom:input_type -> ocean.v1.CreateAccountCustomRequest + 6, // 13: ocean.v1.AccountService.SetAccountLabel:input_type -> ocean.v1.SetAccountLabelRequest + 8, // 14: ocean.v1.AccountService.SetAccountTemplate:input_type -> ocean.v1.SetAccountTemplateRequest + 10, // 15: ocean.v1.AccountService.DeriveAddresses:input_type -> ocean.v1.DeriveAddressesRequest + 12, // 16: ocean.v1.AccountService.DeriveChangeAddresses:input_type -> ocean.v1.DeriveChangeAddressesRequest + 14, // 17: ocean.v1.AccountService.ListAddresses:input_type -> ocean.v1.ListAddressesRequest + 16, // 18: ocean.v1.AccountService.Balance:input_type -> ocean.v1.BalanceRequest + 18, // 19: ocean.v1.AccountService.ListUtxos:input_type -> ocean.v1.ListUtxosRequest + 20, // 20: ocean.v1.AccountService.DeleteAccount:input_type -> ocean.v1.DeleteAccountRequest + 1, // 21: ocean.v1.AccountService.CreateAccountBIP44:output_type -> ocean.v1.CreateAccountBIP44Response + 3, // 22: ocean.v1.AccountService.CreateAccountMultiSig:output_type -> ocean.v1.CreateAccountMultiSigResponse + 5, // 23: ocean.v1.AccountService.CreateAccountCustom:output_type -> ocean.v1.CreateAccountCustomResponse + 7, // 24: ocean.v1.AccountService.SetAccountLabel:output_type -> ocean.v1.SetAccountLabelResponse + 9, // 25: ocean.v1.AccountService.SetAccountTemplate:output_type -> ocean.v1.SetAccountTemplateResponse + 11, // 26: ocean.v1.AccountService.DeriveAddresses:output_type -> ocean.v1.DeriveAddressesResponse + 13, // 27: ocean.v1.AccountService.DeriveChangeAddresses:output_type -> ocean.v1.DeriveChangeAddressesResponse + 15, // 28: ocean.v1.AccountService.ListAddresses:output_type -> ocean.v1.ListAddressesResponse + 17, // 29: ocean.v1.AccountService.Balance:output_type -> ocean.v1.BalanceResponse + 19, // 30: ocean.v1.AccountService.ListUtxos:output_type -> ocean.v1.ListUtxosResponse + 21, // 31: ocean.v1.AccountService.DeleteAccount:output_type -> ocean.v1.DeleteAccountResponse + 21, // [21:32] is the sub-list for method output_type + 10, // [10:21] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_ocean_v1_account_proto_init() } diff --git a/api-spec/protobuf/ocean/v1/account.proto b/api-spec/protobuf/ocean/v1/account.proto index 47b5d99a..da6193f8 100644 --- a/api-spec/protobuf/ocean/v1/account.proto +++ b/api-spec/protobuf/ocean/v1/account.proto @@ -150,6 +150,8 @@ message ListUtxosResponse{ Utxos spendable_utxos = 1; // List of currently locked utxos. Utxos locked_utxos = 2; + // List of unconfirmed utxos. + Utxos unconfirmed_utxos = 3; } message DeleteAccountRequest{ diff --git a/internal/core/application/account_service.go b/internal/core/application/account_service.go index f063a72c..854e34a9 100644 --- a/internal/core/application/account_service.go +++ b/internal/core/application/account_service.go @@ -172,21 +172,30 @@ func (as *AccountService) ListUtxosForAccount( return nil, err } - spendableUtxos, err := as.repoManager.UtxoRepository().GetSpendableUtxosForAccount( + utxos, err := as.repoManager.UtxoRepository().GetAllUtxosForAccount( ctx, account.Namespace, scripts, ) if err != nil { return nil, err } - lockedUtxos, err := as.repoManager.UtxoRepository().GetLockedUtxosForAccount( - ctx, account.Namespace, scripts, - ) - if err != nil { - return nil, err + spendableUtxos := make([]*domain.Utxo, 0, len(utxos)) + unconfirmedUtxos := make([]*domain.Utxo, 0, len(utxos)) + lockedUtxos := make([]*domain.Utxo, 0, len(utxos)) + + for _, u := range utxos { + if u.IsLocked() { + lockedUtxos = append(lockedUtxos, u) + } else { + if u.IsConfirmed() { + spendableUtxos = append(spendableUtxos, u) + } else { + unconfirmedUtxos = append(unconfirmedUtxos, u) + } + } } - return &UtxoInfo{spendableUtxos, lockedUtxos}, nil + return &UtxoInfo{spendableUtxos, lockedUtxos, unconfirmedUtxos}, nil } func (as *AccountService) DeleteAccount( diff --git a/internal/core/application/transaction_service.go b/internal/core/application/transaction_service.go index 9359241c..12ce5864 100644 --- a/internal/core/application/transaction_service.go +++ b/internal/core/application/transaction_service.go @@ -105,7 +105,7 @@ func (ts *TransactionService) SelectUtxos( } utxos, err := ts.repoManager.UtxoRepository().GetSpendableUtxosForAccount( - ctx, account.Namespace, nil, + ctx, account.Namespace, ) if err != nil { return nil, 0, -1, err @@ -396,7 +396,7 @@ func (ts *TransactionService) Transfer( } utxos, err := utxoRepo.GetSpendableUtxosForAccount( - ctx, account.Namespace, nil, + ctx, account.Namespace, ) if err != nil { return "", err @@ -778,7 +778,7 @@ func (ts *TransactionService) scheduleUtxoUnlocker() { for accountName := range w.Accounts { utxos, _ := utxoRepo.GetLockedUtxosForAccount( - ctx, accountName, nil, + ctx, accountName, ) if len(utxos) > 0 { utxosToUnlock := make([]domain.UtxoKey, 0, len(utxos)) diff --git a/internal/core/application/types.go b/internal/core/application/types.go index 5727b301..e02a49aa 100644 --- a/internal/core/application/types.go +++ b/internal/core/application/types.go @@ -55,8 +55,9 @@ type BuildInfo struct { } type UtxoInfo struct { - Spendable Utxos - Locked Utxos + Spendable Utxos + Locked Utxos + Unconfirmed Utxos } type TransactionInfo domain.Transaction diff --git a/internal/core/domain/utxo_repository.go b/internal/core/domain/utxo_repository.go index bb43a289..5e9c1e39 100644 --- a/internal/core/domain/utxo_repository.go +++ b/internal/core/domain/utxo_repository.go @@ -51,15 +51,14 @@ type UtxoRepository interface { // GetSpendableUtxos returns all unlocked utxo UTXOs. GetSpendableUtxos(ctx context.Context) ([]*Utxo, error) // GetAllUtxosForAccount returns the list of all utxos for the given - // account. - GetAllUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error) + // account. Can be filtered by output scripts. + GetAllUtxosForAccount(ctx context.Context, account string, scripts [][]byte) ([]*Utxo, error) // GetSpendableUtxosForAccount returns the list of spendable utxos for the // given account. The list incldues only confirmed and unlocked utxos. - // Can be filtered by output scripts. - GetSpendableUtxosForAccount(ctx context.Context, account string, scripts [][]byte) ([]*Utxo, error) + GetSpendableUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error) // GetLockedUtxosForAccount returns the list of all currently locked utxos - // for the given account. Can be filtered by output scripts. - GetLockedUtxosForAccount(ctx context.Context, account string, scripts [][]byte) ([]*Utxo, error) + // for the given account. + GetLockedUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error) // GetBalanceForAccount returns the confirmed, unconfirmed and locked // balances per each asset for the given account. GetBalanceForAccount(ctx context.Context, account string) (map[string]*Balance, error) diff --git a/internal/infrastructure/storage/db/badger/utxo_repository.go b/internal/infrastructure/storage/db/badger/utxo_repository.go index e1816551..a0d31a7c 100644 --- a/internal/infrastructure/storage/db/badger/utxo_repository.go +++ b/internal/infrastructure/storage/db/badger/utxo_repository.go @@ -76,19 +76,9 @@ func (r *utxoRepository) GetSpendableUtxos( } func (r *utxoRepository) GetAllUtxosForAccount( - ctx context.Context, accountName string, -) ([]*domain.Utxo, error) { - query := badgerhold.Where("AccountName").Eq(accountName) - - return r.findUtxos(ctx, query) -} - -func (r *utxoRepository) GetSpendableUtxosForAccount( ctx context.Context, accountName string, scripts [][]byte, ) ([]*domain.Utxo, error) { - query := badgerhold.Where("SpentStatus").Eq(domain.UtxoStatus{}). - And("ConfirmedStatus").Ne(domain.UtxoStatus{}). - And("LockTimestamp").Eq(int64(0)).And("AccountName").Eq(accountName) + query := badgerhold.Where("AccountName").Eq(accountName) utxos, err := r.findUtxos(ctx, query) if err != nil { @@ -111,37 +101,29 @@ func (r *utxoRepository) GetSpendableUtxosForAccount( return filteredUtxos, nil } -func (r *utxoRepository) GetLockedUtxosForAccount( - ctx context.Context, accountName string, scripts [][]byte, +func (r *utxoRepository) GetSpendableUtxosForAccount( + ctx context.Context, accountName string, ) ([]*domain.Utxo, error) { query := badgerhold.Where("SpentStatus").Eq(domain.UtxoStatus{}). - And("LockTimestamp").Gt(int64(0)).And("AccountName").Eq(accountName) + And("ConfirmedStatus").Ne(domain.UtxoStatus{}). + And("LockTimestamp").Eq(int64(0)).And("AccountName").Eq(accountName) - utxos, err := r.findUtxos(ctx, query) - if err != nil { - return nil, err - } + return r.findUtxos(ctx, query) +} - if len(scripts) <= 0 { - return utxos, nil - } +func (r *utxoRepository) GetLockedUtxosForAccount( + ctx context.Context, accountName string, +) ([]*domain.Utxo, error) { + query := badgerhold.Where("SpentStatus").Eq(domain.UtxoStatus{}). + And("LockTimestamp").Gt(int64(0)).And("AccountName").Eq(accountName) - filteredUtxos := make([]*domain.Utxo, 0, len(utxos)) - for _, u := range utxos { - for _, script := range scripts { - if bytes.Equal(u.Script, script) { - filteredUtxos = append(filteredUtxos, u) - break - } - } - } - return filteredUtxos, nil + return r.findUtxos(ctx, query) } func (r *utxoRepository) GetBalanceForAccount( ctx context.Context, accountName string, ) (map[string]*domain.Balance, error) { - utxos, err := r.GetAllUtxosForAccount(ctx, accountName) + utxos, err := r.GetAllUtxosForAccount(ctx, accountName, nil) if err != nil { return nil, err } diff --git a/internal/infrastructure/storage/db/inmemory/utxo_repository.go b/internal/infrastructure/storage/db/inmemory/utxo_repository.go index ad86b7fb..d2f5e293 100644 --- a/internal/infrastructure/storage/db/inmemory/utxo_repository.go +++ b/internal/infrastructure/storage/db/inmemory/utxo_repository.go @@ -80,30 +80,30 @@ func (r *utxoRepository) GetSpendableUtxos(_ context.Context) ([]*domain.Utxo, e } func (r *utxoRepository) GetAllUtxosForAccount( - _ context.Context, account string, + _ context.Context, account string, scripts [][]byte, ) ([]*domain.Utxo, error) { r.store.lock.RLock() defer r.store.lock.RUnlock() - return r.getUtxosForAccount(account, false, false, nil) + return r.getUtxosForAccount(account, false, false, scripts) } func (r *utxoRepository) GetSpendableUtxosForAccount( - _ context.Context, account string, scripts [][]byte, + _ context.Context, account string, ) ([]*domain.Utxo, error) { r.store.lock.RLock() defer r.store.lock.RUnlock() - return r.getUtxosForAccount(account, true, false, scripts) + return r.getUtxosForAccount(account, true, false, nil) } func (r *utxoRepository) GetLockedUtxosForAccount( - _ context.Context, account string, scripts [][]byte, + _ context.Context, account string, ) ([]*domain.Utxo, error) { r.store.lock.RLock() defer r.store.lock.RUnlock() - return r.getUtxosForAccount(account, false, true, scripts) + return r.getUtxosForAccount(account, false, true, nil) } func (r *utxoRepository) GetBalanceForAccount( diff --git a/internal/infrastructure/storage/db/postgres/utxo_repository.go b/internal/infrastructure/storage/db/postgres/utxo_repository.go index 76f9cd07..31f32479 100644 --- a/internal/infrastructure/storage/db/postgres/utxo_repository.go +++ b/internal/infrastructure/storage/db/postgres/utxo_repository.go @@ -239,7 +239,7 @@ func (u *utxoRepositoryPg) GetSpendableUtxos( } func (u *utxoRepositoryPg) GetAllUtxosForAccount( - ctx context.Context, account string, + ctx context.Context, account string, scripts [][]byte, ) ([]*domain.Utxo, error) { resp := make([]*domain.Utxo, 0) utxos, err := u.querier.GetUtxosForAccount(ctx, account) @@ -262,14 +262,23 @@ func (u *utxoRepositoryPg) GetAllUtxosForAccount( } for _, v := range utxosByKey { - resp = append(resp, v) + found := len(scripts) <= 0 + for _, script := range scripts { + if bytes.Equal(v.Script, script) { + found = true + break + } + } + if found { + resp = append(resp, v) + } } return resp, nil } func (u *utxoRepositoryPg) GetSpendableUtxosForAccount( - ctx context.Context, account string, scripts [][]byte, + ctx context.Context, account string, ) ([]*domain.Utxo, error) { resp := make([]*domain.Utxo, 0) utxos, err := u.querier.GetUtxosForAccount(ctx, account) @@ -293,16 +302,7 @@ func (u *utxoRepositoryPg) GetSpendableUtxosForAccount( for _, v := range utxosByKey { if !v.IsLocked() && v.IsConfirmed() && !v.IsSpent() { - found := len(scripts) <= 0 - for _, script := range scripts { - if bytes.Equal(v.Script, script) { - found = true - break - } - } - if found { - resp = append(resp, v) - } + resp = append(resp, v) } } @@ -310,7 +310,7 @@ func (u *utxoRepositoryPg) GetSpendableUtxosForAccount( } func (u *utxoRepositoryPg) GetLockedUtxosForAccount( - ctx context.Context, account string, scripts [][]byte, + ctx context.Context, account string, ) ([]*domain.Utxo, error) { resp := make([]*domain.Utxo, 0) utxos, err := u.querier.GetUtxosForAccount(ctx, account) @@ -334,16 +334,7 @@ func (u *utxoRepositoryPg) GetLockedUtxosForAccount( for _, v := range utxosByKey { if v.IsLocked() { - found := len(scripts) <= 0 - for _, script := range scripts { - if bytes.Equal(v.Script, script) { - found = true - break - } - } - if found { - resp = append(resp, v) - } + resp = append(resp, v) } } diff --git a/internal/infrastructure/storage/db/test/utxo_repository_test.go b/internal/infrastructure/storage/db/test/utxo_repository_test.go index 5d069095..8db818c2 100644 --- a/internal/infrastructure/storage/db/test/utxo_repository_test.go +++ b/internal/infrastructure/storage/db/test/utxo_repository_test.go @@ -70,11 +70,11 @@ func testAddAndGetUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) - utxos, err = repo.GetAllUtxosForAccount(ctx, accountName) + utxos, err = repo.GetAllUtxosForAccount(ctx, accountName, nil) require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) - utxos, err = repo.GetAllUtxosForAccount(ctx, wrongAccountName) + utxos, err = repo.GetAllUtxosForAccount(ctx, wrongAccountName, nil) require.NoError(t, err) require.Empty(t, utxos) @@ -82,11 +82,11 @@ func testAddAndGetUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Empty(t, utxos) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) - utxos, err = repo.GetLockedUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetLockedUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) @@ -140,7 +140,7 @@ func testConfirmUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) @@ -166,7 +166,7 @@ func testLockUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Zero(t, count) - utxos, err := repo.GetLockedUtxosForAccount(ctx, accountName, nil) + utxos, err := repo.GetLockedUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) @@ -174,7 +174,7 @@ func testLockUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Empty(t, utxos) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) @@ -200,7 +200,7 @@ func testUnlockUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Zero(t, count) - utxos, err := repo.GetLockedUtxosForAccount(ctx, accountName, nil) + utxos, err := repo.GetLockedUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) @@ -208,7 +208,7 @@ func testUnlockUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Len(t, utxos, len(newUtxos)) @@ -238,7 +238,7 @@ func testSpendUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Empty(t, utxos) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) @@ -268,7 +268,7 @@ func testConfirmSpentUtxos(t *testing.T, repo domain.UtxoRepository) { require.NoError(t, err) require.Empty(t, utxos) - utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName, nil) + utxos, err = repo.GetSpendableUtxosForAccount(ctx, accountName) require.NoError(t, err) require.Empty(t, utxos) diff --git a/internal/interfaces/grpc/handler/account.go b/internal/interfaces/grpc/handler/account.go index a26f94d8..06aa6d05 100644 --- a/internal/interfaces/grpc/handler/account.go +++ b/internal/interfaces/grpc/handler/account.go @@ -190,6 +190,7 @@ func (a *account) ListUtxos( } spendableUtxos := parseUtxos(utxosInfo.Spendable.Info()) lockedUtxos := parseUtxos(utxosInfo.Locked.Info()) + unconfirmedUtxos := parseUtxos(utxosInfo.Unconfirmed.Info()) return &pb.ListUtxosResponse{ SpendableUtxos: &pb.Utxos{ AccountName: name, @@ -199,6 +200,10 @@ func (a *account) ListUtxos( AccountName: name, Utxos: lockedUtxos, }, + UnconfirmedUtxos: &pb.Utxos{ + AccountName: name, + Utxos: unconfirmedUtxos, + }, }, nil }