Add endpoint to fetch pubkey & Require wallet already unlocked when starting the service (#43)

* Add endpoint to fetch pubkey & simplify ports.Wallet

* Lint
This commit is contained in:
Pietralberto Mazza
2023-12-05 17:45:38 +01:00
committed by GitHub
parent 376d62f44b
commit 7bcdff0d2a
14 changed files with 425 additions and 563 deletions

View File

@@ -203,6 +203,28 @@
]
}
},
"/v1/pubkey": {
"get": {
"operationId": "ArkService_GetPubkey",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetPubkeyResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"ArkService"
]
}
},
"/v1/round/{txid}": {
"get": {
"operationId": "ArkService_GetRound",
@@ -343,6 +365,14 @@
}
}
},
"v1GetPubkeyResponse": {
"type": "object",
"properties": {
"pubkey": {
"type": "string"
}
}
},
"v1GetRoundResponse": {
"type": "object",
"properties": {

View File

@@ -48,6 +48,11 @@ service ArkService {
get: "/v1/vtxos/{address}"
};
}
rpc GetPubkey(GetPubkeyRequest) returns (GetPubkeyResponse) {
option (google.api.http) = {
get: "/v1/pubkey"
};
}
}
message RegisterPaymentRequest {
@@ -150,3 +155,8 @@ message Vtxo {
bool spent = 3;
}
message GetPubkeyRequest {}
message GetPubkeyResponse {
string pubkey = 1;
}

View File

@@ -1220,6 +1220,91 @@ func (x *Vtxo) GetSpent() bool {
return false
}
type GetPubkeyRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *GetPubkeyRequest) Reset() {
*x = GetPubkeyRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_ark_v1_service_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetPubkeyRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetPubkeyRequest) ProtoMessage() {}
func (x *GetPubkeyRequest) ProtoReflect() protoreflect.Message {
mi := &file_ark_v1_service_proto_msgTypes[23]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetPubkeyRequest.ProtoReflect.Descriptor instead.
func (*GetPubkeyRequest) Descriptor() ([]byte, []int) {
return file_ark_v1_service_proto_rawDescGZIP(), []int{23}
}
type GetPubkeyResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Pubkey string `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"`
}
func (x *GetPubkeyResponse) Reset() {
*x = GetPubkeyResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_ark_v1_service_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetPubkeyResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetPubkeyResponse) ProtoMessage() {}
func (x *GetPubkeyResponse) ProtoReflect() protoreflect.Message {
mi := &file_ark_v1_service_proto_msgTypes[24]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetPubkeyResponse.ProtoReflect.Descriptor instead.
func (*GetPubkeyResponse) Descriptor() ([]byte, []int) {
return file_ark_v1_service_proto_rawDescGZIP(), []int{24}
}
func (x *GetPubkeyResponse) GetPubkey() string {
if x != nil {
return x.Pubkey
}
return ""
}
var File_ark_v1_service_proto protoreflect.FileDescriptor
var file_ark_v1_service_proto_rawDesc = []byte{
@@ -1329,68 +1414,77 @@ var file_ark_v1_service_proto_rawDesc = []byte{
0x65, 0x69, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x72,
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x52, 0x08, 0x72, 0x65, 0x63,
0x65, 0x69, 0x76, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x70, 0x65, 0x6e, 0x74, 0x18, 0x03,
0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x70, 0x65, 0x6e, 0x74, 0x32, 0xa7, 0x06, 0x0a, 0x0a,
0x41, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x73, 0x0a, 0x0f, 0x52, 0x65,
0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e,
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50,
0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e,
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50,
0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70,
0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12,
0x67, 0x0a, 0x0c, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61, 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, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 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, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93,
0x02, 0x16, 0x3a, 0x01, 0x2a, 0x22, 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65,
0x6e, 0x74, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x73, 0x0a, 0x0f, 0x46, 0x69, 0x6e, 0x61,
0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x61, 0x72,
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79,
0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x72,
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79,
0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3,
0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79,
0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x12, 0x57, 0x0a,
0x08, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x12, 0x17, 0x2e, 0x61, 0x72, 0x6b, 0x2e,
0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52,
0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3,
0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x2f,
0x7b, 0x74, 0x78, 0x69, 0x64, 0x7d, 0x12, 0x65, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65,
0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76,
0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x70, 0x65, 0x6e, 0x74, 0x22, 0x12, 0x0a, 0x10, 0x47,
0x65, 0x74, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22,
0x2b, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x32, 0xfd, 0x06, 0x0a,
0x0a, 0x41, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x73, 0x0a, 0x0f, 0x52,
0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e,
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f,
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f,
0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
0x12, 0x67, 0x0a, 0x0c, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x61, 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, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 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, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4,
0x93, 0x02, 0x16, 0x3a, 0x01, 0x2a, 0x22, 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d,
0x65, 0x6e, 0x74, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x73, 0x0a, 0x0f, 0x46, 0x69, 0x6e,
0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x61,
0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61,
0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61,
0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x50, 0x61,
0x79, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82,
0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61,
0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x12, 0x57,
0x0a, 0x08, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x12, 0x17, 0x2e, 0x61, 0x72, 0x6b,
0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74,
0x52, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82,
0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x6e, 0x64,
0x2f, 0x7b, 0x74, 0x78, 0x69, 0x64, 0x7d, 0x12, 0x65, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x76,
0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x2e, 0x61, 0x72, 0x6b, 0x2e,
0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76,
0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31,
0x2e, 0x47, 0x65, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c, 0x12,
0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x30, 0x01, 0x12, 0x50, 0x0a,
0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50,
0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x72, 0x6b,
0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x12, 0x15, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x69,
0x6e, 0x67, 0x2f, 0x7b, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x7d, 0x12,
0x55, 0x0a, 0x06, 0x46, 0x61, 0x75, 0x63, 0x65, 0x74, 0x12, 0x15, 0x2e, 0x61, 0x72, 0x6b, 0x2e,
0x76, 0x31, 0x2e, 0x46, 0x61, 0x75, 0x63, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x16, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x61, 0x75, 0x63, 0x65, 0x74,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16,
0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x61, 0x75, 0x63, 0x65, 0x74, 0x2f, 0x7b, 0x61, 0x64,
0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, 0x5d, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74,
0x78, 0x6f, 0x73, 0x12, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73,
0x74, 0x56, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e,
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74, 0x78, 0x6f, 0x73,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15,
0x12, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x76, 0x74, 0x78, 0x6f, 0x73, 0x2f, 0x7b, 0x61, 0x64, 0x64,
0x72, 0x65, 0x73, 0x73, 0x7d, 0x42, 0x92, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72,
0x6b, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f,
0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x61, 0x72, 0x6b, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x61, 0x72, 0x6b,
0x2f, 0x61, 0x70, 0x69, 0x2d, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x72,
0x6b, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x41, 0x72, 0x6b, 0x2e,
0x56, 0x31, 0xca, 0x02, 0x06, 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,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c,
0x12, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x30, 0x01, 0x12, 0x50,
0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e,
0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x72,
0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x12, 0x15, 0x2f, 0x76, 0x31, 0x2f, 0x70,
0x69, 0x6e, 0x67, 0x2f, 0x7b, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x7d,
0x12, 0x55, 0x0a, 0x06, 0x46, 0x61, 0x75, 0x63, 0x65, 0x74, 0x12, 0x15, 0x2e, 0x61, 0x72, 0x6b,
0x2e, 0x76, 0x31, 0x2e, 0x46, 0x61, 0x75, 0x63, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x16, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x61, 0x75, 0x63, 0x65,
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02,
0x16, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x61, 0x75, 0x63, 0x65, 0x74, 0x2f, 0x7b, 0x61,
0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, 0x5d, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x56,
0x74, 0x78, 0x6f, 0x73, 0x12, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69,
0x73, 0x74, 0x56, 0x74, 0x78, 0x6f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19,
0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x74, 0x78, 0x6f,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02,
0x15, 0x12, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x76, 0x74, 0x78, 0x6f, 0x73, 0x2f, 0x7b, 0x61, 0x64,
0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, 0x54, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x50, 0x75, 0x62,
0x6b, 0x65, 0x79, 0x12, 0x18, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74,
0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e,
0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c,
0x12, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x42, 0x92, 0x01, 0x0a,
0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x6b, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74,
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x6b, 0x2d, 0x6e, 0x65, 0x74, 0x77,
0x6f, 0x72, 0x6b, 0x2f, 0x61, 0x72, 0x6b, 0x2f, 0x61, 0x70, 0x69, 0x2d, 0x73, 0x70, 0x65, 0x63,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x72,
0x6b, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x72, 0x6b, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58,
0xaa, 0x02, 0x06, 0x41, 0x72, 0x6b, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x06, 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 (
@@ -1405,7 +1499,7 @@ func file_ark_v1_service_proto_rawDescGZIP() []byte {
return file_ark_v1_service_proto_rawDescData
}
var file_ark_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_ark_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 26)
var file_ark_v1_service_proto_goTypes = []interface{}{
(*RegisterPaymentRequest)(nil), // 0: ark.v1.RegisterPaymentRequest
(*RegisterPaymentResponse)(nil), // 1: ark.v1.RegisterPaymentResponse
@@ -1430,13 +1524,15 @@ var file_ark_v1_service_proto_goTypes = []interface{}{
(*ListVtxosRequest)(nil), // 20: ark.v1.ListVtxosRequest
(*ListVtxosResponse)(nil), // 21: ark.v1.ListVtxosResponse
(*Vtxo)(nil), // 22: ark.v1.Vtxo
nil, // 23: ark.v1.RoundFinalizationEvent.ForfeitTxsEntry
(*GetPubkeyRequest)(nil), // 23: ark.v1.GetPubkeyRequest
(*GetPubkeyResponse)(nil), // 24: ark.v1.GetPubkeyResponse
nil, // 25: ark.v1.RoundFinalizationEvent.ForfeitTxsEntry
}
var file_ark_v1_service_proto_depIdxs = []int32{
9, // 0: ark.v1.RegisterPaymentRequest.inputs:type_name -> ark.v1.Input
10, // 1: ark.v1.ClaimPaymentRequest.outputs:type_name -> ark.v1.Output
8, // 2: ark.v1.GetRoundResponse.round:type_name -> ark.v1.Round
23, // 3: ark.v1.RoundFinalizationEvent.forfeit_txs:type_name -> ark.v1.RoundFinalizationEvent.ForfeitTxsEntry
25, // 3: ark.v1.RoundFinalizationEvent.forfeit_txs:type_name -> ark.v1.RoundFinalizationEvent.ForfeitTxsEntry
11, // 4: ark.v1.GetEventStreamResponse.round_finalization:type_name -> ark.v1.RoundFinalizationEvent
12, // 5: ark.v1.GetEventStreamResponse.round_finalized:type_name -> ark.v1.RoundFinalizedEvent
13, // 6: ark.v1.GetEventStreamResponse.round_failed:type_name -> ark.v1.RoundFailed
@@ -1451,16 +1547,18 @@ var file_ark_v1_service_proto_depIdxs = []int32{
16, // 15: ark.v1.ArkService.Ping:input_type -> ark.v1.PingRequest
18, // 16: ark.v1.ArkService.Faucet:input_type -> ark.v1.FaucetRequest
20, // 17: ark.v1.ArkService.ListVtxos:input_type -> ark.v1.ListVtxosRequest
1, // 18: ark.v1.ArkService.RegisterPayment:output_type -> ark.v1.RegisterPaymentResponse
3, // 19: ark.v1.ArkService.ClaimPayment:output_type -> ark.v1.ClaimPaymentResponse
5, // 20: ark.v1.ArkService.FinalizePayment:output_type -> ark.v1.FinalizePaymentResponse
7, // 21: ark.v1.ArkService.GetRound:output_type -> ark.v1.GetRoundResponse
15, // 22: ark.v1.ArkService.GetEventStream:output_type -> ark.v1.GetEventStreamResponse
17, // 23: ark.v1.ArkService.Ping:output_type -> ark.v1.PingResponse
19, // 24: ark.v1.ArkService.Faucet:output_type -> ark.v1.FaucetResponse
21, // 25: ark.v1.ArkService.ListVtxos:output_type -> ark.v1.ListVtxosResponse
18, // [18:26] is the sub-list for method output_type
10, // [10:18] is the sub-list for method input_type
23, // 18: ark.v1.ArkService.GetPubkey:input_type -> ark.v1.GetPubkeyRequest
1, // 19: ark.v1.ArkService.RegisterPayment:output_type -> ark.v1.RegisterPaymentResponse
3, // 20: ark.v1.ArkService.ClaimPayment:output_type -> ark.v1.ClaimPaymentResponse
5, // 21: ark.v1.ArkService.FinalizePayment:output_type -> ark.v1.FinalizePaymentResponse
7, // 22: ark.v1.ArkService.GetRound:output_type -> ark.v1.GetRoundResponse
15, // 23: ark.v1.ArkService.GetEventStream:output_type -> ark.v1.GetEventStreamResponse
17, // 24: ark.v1.ArkService.Ping:output_type -> ark.v1.PingResponse
19, // 25: ark.v1.ArkService.Faucet:output_type -> ark.v1.FaucetResponse
21, // 26: ark.v1.ArkService.ListVtxos:output_type -> ark.v1.ListVtxosResponse
24, // 27: ark.v1.ArkService.GetPubkey:output_type -> ark.v1.GetPubkeyResponse
19, // [19:28] is the sub-list for method output_type
10, // [10:19] 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
@@ -1748,6 +1846,30 @@ func file_ark_v1_service_proto_init() {
return nil
}
}
file_ark_v1_service_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetPubkeyRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_ark_v1_service_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetPubkeyResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_ark_v1_service_proto_msgTypes[15].OneofWrappers = []interface{}{
(*GetEventStreamResponse_RoundFinalization)(nil),
@@ -1760,7 +1882,7 @@ func file_ark_v1_service_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_ark_v1_service_proto_rawDesc,
NumEnums: 0,
NumMessages: 24,
NumMessages: 26,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -358,6 +358,24 @@ func local_request_ArkService_ListVtxos_0(ctx context.Context, marshaler runtime
}
func request_ArkService_GetPubkey_0(ctx context.Context, marshaler runtime.Marshaler, client ArkServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetPubkeyRequest
var metadata runtime.ServerMetadata
msg, err := client.GetPubkey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_ArkService_GetPubkey_0(ctx context.Context, marshaler runtime.Marshaler, server ArkServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetPubkeyRequest
var metadata runtime.ServerMetadata
msg, err := server.GetPubkey(ctx, &protoReq)
return msg, metadata, err
}
// RegisterArkServiceHandlerServer registers the http handlers for service ArkService to "mux".
// UnaryRPC :call ArkServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@@ -532,6 +550,29 @@ func RegisterArkServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux,
})
mux.Handle("GET", pattern_ArkService_GetPubkey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/ark.v1.ArkService/GetPubkey", runtime.WithHTTPPathPattern("/v1/pubkey"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_ArkService_GetPubkey_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_ArkService_GetPubkey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -733,6 +774,26 @@ func RegisterArkServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux,
})
mux.Handle("GET", pattern_ArkService_GetPubkey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/ark.v1.ArkService/GetPubkey", runtime.WithHTTPPathPattern("/v1/pubkey"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_ArkService_GetPubkey_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_ArkService_GetPubkey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -752,6 +813,8 @@ var (
pattern_ArkService_Faucet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "faucet", "address"}, ""))
pattern_ArkService_ListVtxos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "vtxos", "address"}, ""))
pattern_ArkService_GetPubkey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "pubkey"}, ""))
)
var (
@@ -770,4 +833,6 @@ var (
forward_ArkService_Faucet_0 = runtime.ForwardResponseMessage
forward_ArkService_ListVtxos_0 = runtime.ForwardResponseMessage
forward_ArkService_GetPubkey_0 = runtime.ForwardResponseMessage
)

View File

@@ -26,6 +26,7 @@ type ArkServiceClient interface {
Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error)
Faucet(ctx context.Context, in *FaucetRequest, opts ...grpc.CallOption) (*FaucetResponse, error)
ListVtxos(ctx context.Context, in *ListVtxosRequest, opts ...grpc.CallOption) (*ListVtxosResponse, error)
GetPubkey(ctx context.Context, in *GetPubkeyRequest, opts ...grpc.CallOption) (*GetPubkeyResponse, error)
}
type arkServiceClient struct {
@@ -131,6 +132,15 @@ func (c *arkServiceClient) ListVtxos(ctx context.Context, in *ListVtxosRequest,
return out, nil
}
func (c *arkServiceClient) GetPubkey(ctx context.Context, in *GetPubkeyRequest, opts ...grpc.CallOption) (*GetPubkeyResponse, error) {
out := new(GetPubkeyResponse)
err := c.cc.Invoke(ctx, "/ark.v1.ArkService/GetPubkey", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ArkServiceServer is the server API for ArkService service.
// All implementations should embed UnimplementedArkServiceServer
// for forward compatibility
@@ -143,6 +153,7 @@ type ArkServiceServer interface {
Ping(context.Context, *PingRequest) (*PingResponse, error)
Faucet(context.Context, *FaucetRequest) (*FaucetResponse, error)
ListVtxos(context.Context, *ListVtxosRequest) (*ListVtxosResponse, error)
GetPubkey(context.Context, *GetPubkeyRequest) (*GetPubkeyResponse, error)
}
// UnimplementedArkServiceServer should be embedded to have forward compatible implementations.
@@ -173,6 +184,9 @@ func (UnimplementedArkServiceServer) Faucet(context.Context, *FaucetRequest) (*F
func (UnimplementedArkServiceServer) ListVtxos(context.Context, *ListVtxosRequest) (*ListVtxosResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListVtxos not implemented")
}
func (UnimplementedArkServiceServer) GetPubkey(context.Context, *GetPubkeyRequest) (*GetPubkeyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPubkey not implemented")
}
// UnsafeArkServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ArkServiceServer will
@@ -332,6 +346,24 @@ func _ArkService_ListVtxos_Handler(srv interface{}, ctx context.Context, dec fun
return interceptor(ctx, in, info, handler)
}
func _ArkService_GetPubkey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPubkeyRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ArkServiceServer).GetPubkey(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ark.v1.ArkService/GetPubkey",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ArkServiceServer).GetPubkey(ctx, req.(*GetPubkeyRequest))
}
return interceptor(ctx, in, info, handler)
}
// ArkService_ServiceDesc is the grpc.ServiceDesc for ArkService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -367,6 +399,10 @@ var ArkService_ServiceDesc = grpc.ServiceDesc{
MethodName: "ListVtxos",
Handler: _ArkService_ListVtxos_Handler,
},
{
MethodName: "GetPubkey",
Handler: _ArkService_GetPubkey_Handler,
},
},
Streams: []grpc.StreamDesc{
{

View File

@@ -37,12 +37,14 @@ type Service interface {
GetEventsChannel(ctx context.Context) <-chan domain.RoundEvent
UpdatePaymentStatus(ctx context.Context, id string) error
ListVtxos(ctx context.Context, pubkey string) ([]domain.Vtxo, error)
GetPubkey(ctx context.Context) (string, error)
}
type service struct {
roundInterval int64
network common.Network
onchainNework network.Network
pubkey string
wallet ports.WalletService
scheduler ports.SchedulerService
@@ -59,12 +61,14 @@ func NewService(
walletSvc ports.WalletService, schedulerSvc ports.SchedulerService,
repoManager ports.RepoManager, builder ports.TxBuilder,
) Service {
pubkey := ""
eventsCh := make(chan domain.RoundEvent)
paymentRequests := newPaymentsMap(nil)
forfeitTxs := newForfeitTxsMap()
svc := &service{
interval, network, onchainNetwork,
interval, network, onchainNetwork, pubkey,
walletSvc, schedulerSvc, repoManager, builder, paymentRequests, forfeitTxs,
make(chan domain.RoundEvent),
eventsCh,
}
repoManager.RegisterEventsHandler(
func(round *domain.Round) {
@@ -171,6 +175,21 @@ func (s *service) GetRoundByTxid(ctx context.Context, poolTxid string) (*domain.
return s.repoManager.Rounds().GetRoundWithTxid(ctx, poolTxid)
}
func (s *service) GetPubkey(ctx context.Context) (string, error) {
if s.pubkey == "" {
pubkey, err := s.wallet.GetPubkey(ctx)
if err != nil {
return "", err
}
serializedPubkey, err := common.EncodePubKey(s.network.PubKey, pubkey)
if err != nil {
return "", err
}
s.pubkey = serializedPubkey
}
return s.pubkey, nil
}
func (s *service) start() error {
startImmediately := true
finalizationInterval := int64(s.roundInterval / 2)
@@ -283,7 +302,7 @@ func (s *service) finalizeRound() {
return
}
txid, err := s.wallet.Transaction().BroadcastTransaction(ctx, round.TxHex)
txid, err := s.wallet.BroadcastTransaction(ctx, round.TxHex)
if err != nil {
round.Fail(fmt.Errorf("failed to broadcast pool tx: %s", err))
log.WithError(err).Warn("failed to broadcast pool tx")

View File

@@ -1,35 +1,15 @@
package ports
import "context"
import (
"context"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
type WalletService interface {
Wallet() Wallet
Account() Account
Transaction() Transaction
Notification() Notification
Close()
}
type Wallet interface {
GenSeed(ctx context.Context) ([]string, error)
InitWallet(ctx context.Context, mnemonic []string, password string) error
Unlock(ctx context.Context, password string) error
Lock(ctx context.Context, password string) error
Status(ctx context.Context) (WalletStatus, error)
}
type Account interface {
GetPubkey(ctx context.Context) (*secp256k1.PublicKey, error)
DeriveAddresses(ctx context.Context, num int) ([]string, error)
GetBalance(ctx context.Context) (map[string]Balance, error)
ListUtxos(ctx context.Context) ([]Utxo, []Utxo, error)
}
type Transaction interface {
GetTransaction(ctx context.Context, txid string) (string, error)
UpdatePset(
ctx context.Context, pset string,
ins []TxInput, outs []TxOutput,
) (string, error)
SignPset(
ctx context.Context, pset string, extractRawTx bool,
) (string, error)
@@ -37,71 +17,15 @@ type Transaction interface {
BroadcastTransaction(ctx context.Context, txHex string) (string, error)
}
type Notification interface {
GetTxNotifications() chan WalletTxNotification
GetUtxoNotifications() chan WalletUtxoNotification
}
type WalletStatus interface {
IsInitialized() bool
IsUnlocked() bool
IsSynced() bool
}
type WalletTxNotification interface {
GetEventType() WalletTxEventType
GetAccountNames() []string
GetTxHex() string
GetBlockDetails() BlockInfo
}
type WalletUtxoNotification interface {
GetEventType() WalletUtxoEventType
GetUtxos() []Utxo
}
type WalletTxEventType interface {
IsUnconfirmed() bool
IsConfirmed() bool
IsBroadcasted() bool
}
type WalletUtxoEventType interface {
IsUnconfirmed() bool
IsConfirmed() bool
IsLocked() bool
IsUnlocked() bool
IsSpent() bool
}
type Balance interface {
GetConfirmedBalance() uint64
GetUnconfirmedBalance() uint64
GetLockedBalance() uint64
GetTotalBalance() uint64
}
type UtxoKey interface {
type TxInput interface {
GetTxid() string
GetIndex() uint32
}
type UtxoStatus interface {
GetTxid() string
GetBlockInfo() BlockInfo
}
type Utxo interface {
UtxoKey
GetAsset() string
GetValue() uint64
GetScript() string
GetConfirmedStatus() UtxoStatus
GetSpentStatus() UtxoStatus
}
type TxInput interface {
UtxoKey
GetScript() string
GetScriptSigSize() int
GetWitnessSize() int
@@ -111,9 +35,3 @@ type TxOutput interface {
GetAmount() uint64
GetScript() string
}
type BlockInfo interface {
GetHash() string
GetHeight() uint64
GetTimestamp() int64
}

View File

@@ -4,23 +4,13 @@ import (
"context"
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/ports"
"github.com/vulpemventures/go-elements/address"
"google.golang.org/grpc"
)
type account struct {
client pb.AccountServiceClient
}
func newAccount(conn *grpc.ClientConn) *account {
return &account{pb.NewAccountServiceClient(conn)}
}
func (m *account) DeriveAddresses(
func (s *service) DeriveAddresses(
ctx context.Context, numOfAddresses int,
) ([]string, error) {
res, err := m.client.DeriveAddresses(ctx, &pb.DeriveAddressesRequest{
res, err := s.accountClient.DeriveAddresses(ctx, &pb.DeriveAddressesRequest{
AccountName: accountLabel,
NumOfAddresses: uint64(numOfAddresses),
})
@@ -36,47 +26,3 @@ func (m *account) DeriveAddresses(
}
return addresses, nil
}
func (m *account) GetBalance(
ctx context.Context,
) (map[string]ports.Balance, error) {
res, err := m.client.Balance(ctx, &pb.BalanceRequest{
AccountName: accountLabel,
})
if err != nil {
return nil, err
}
balance := make(map[string]ports.Balance)
for asset, bal := range res.GetBalance() {
balance[asset] = bal
}
return balance, nil
}
func (m *account) ListUtxos(
ctx context.Context,
) (spendableUtxos, lockedUtxos []ports.Utxo, err error) {
res, err := m.client.ListUtxos(ctx, &pb.ListUtxosRequest{
AccountName: accountLabel,
})
if err != nil {
return nil, nil, err
}
if res.GetSpendableUtxos() != nil {
spendableUtxos = utxoList(res.GetSpendableUtxos().GetUtxos()).toPortableList()
}
if res.GetLockedUtxos() != nil {
lockedUtxos = utxoList(res.GetLockedUtxos().GetUtxos()).toPortableList()
}
return
}
type utxoList []*pb.Utxo
func (l utxoList) toPortableList() []ports.Utxo {
utxos := make([]ports.Utxo, 0, len(l))
for _, u := range l {
utxos = append(utxos, utxoInfo{u})
}
return utxos
}

View File

@@ -1,195 +0,0 @@
package oceanwallet
import (
"context"
"fmt"
"io"
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/ports"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
type notify struct {
client pb.NotificationServiceClient
chTxNotifications chan ports.WalletTxNotification
chUtxoNotifications chan ports.WalletUtxoNotification
}
func newNotify(conn *grpc.ClientConn) (*notify, error) {
svc := &notify{
client: pb.NewNotificationServiceClient(conn),
chTxNotifications: make(chan ports.WalletTxNotification),
chUtxoNotifications: make(chan ports.WalletUtxoNotification),
}
txStream, err := svc.client.TransactionNotifications(
context.Background(), &pb.TransactionNotificationsRequest{},
)
if err != nil {
return nil, fmt.Errorf(
"failed to open stream for tx notifications: %s", err,
)
}
go svc.startListeningForTxNotifications(txStream)
utxoStream, err := svc.client.UtxosNotifications(
context.Background(), &pb.UtxosNotificationsRequest{},
)
if err != nil {
return nil, fmt.Errorf(
"failed to open stream for utxo notifications: %s", err,
)
}
go svc.startListeningForUtxoNotifications(utxoStream)
return svc, nil
}
func (m *notify) GetTxNotifications() chan ports.WalletTxNotification {
return m.chTxNotifications
}
func (m *notify) GetUtxoNotifications() chan ports.WalletUtxoNotification {
return m.chUtxoNotifications
}
func (m *notify) startListeningForTxNotifications(
stream pb.NotificationService_TransactionNotificationsClient,
) {
var err error
defer func() {
if err != nil {
log.WithError(err).Fatal(
"notification handler: error while listenting to tx notifications",
)
}
}()
for {
var notification *pb.TransactionNotificationsResponse
notification, err = stream.Recv()
if err != nil {
if err == io.EOF {
break
}
return
}
select {
case m.chTxNotifications <- txNotifyInfo{notification}:
continue
default:
}
}
}
func (m *notify) startListeningForUtxoNotifications(
stream pb.NotificationService_UtxosNotificationsClient,
) {
var err error
defer func() {
if err != nil {
log.WithError(err).Fatal(
"notification handler: error while listenting to utxo notifications",
)
}
}()
for {
var notification *pb.UtxosNotificationsResponse
notification, err = stream.Recv()
if err != nil {
if err == io.EOF {
break
}
return
}
select {
case m.chUtxoNotifications <- utxoNotifyInfo{notification}:
continue
default:
}
}
}
type txNotifyInfo struct {
*pb.TransactionNotificationsResponse
}
func (i txNotifyInfo) GetEventType() ports.WalletTxEventType {
return txEventType(i.TransactionNotificationsResponse.GetEventType())
}
func (i txNotifyInfo) GetTxHex() string {
return i.TransactionNotificationsResponse.GetTxhex()
}
func (i txNotifyInfo) GetBlockDetails() ports.BlockInfo {
return i.TransactionNotificationsResponse.GetBlockDetails()
}
type txEventType pb.TxEventType
func (t txEventType) IsUnconfirmed() bool {
return int(t) == int(pb.TxEventType_TX_EVENT_TYPE_UNCONFIRMED)
}
func (t txEventType) IsConfirmed() bool {
return int(t) == int(pb.TxEventType_TX_EVENT_TYPE_CONFIRMED)
}
func (t txEventType) IsBroadcasted() bool {
return int(t) == int(pb.TxEventType_TX_EVENT_TYPE_BROADCASTED)
}
type utxoNotifyInfo struct {
*pb.UtxosNotificationsResponse
}
func (i utxoNotifyInfo) GetEventType() ports.WalletUtxoEventType {
return utxoEventType(i.UtxosNotificationsResponse.GetEventType())
}
func (i utxoNotifyInfo) GetUtxos() []ports.Utxo {
utxos := make([]ports.Utxo, 0, len(i.UtxosNotificationsResponse.GetUtxos()))
for _, u := range i.UtxosNotificationsResponse.GetUtxos() {
utxos = append(utxos, utxoInfo{u})
}
return utxos
}
type utxoEventType pb.UtxoEventType
func (t utxoEventType) IsUnconfirmed() bool {
return int(t) == int(pb.UtxoEventType_UTXO_EVENT_TYPE_NEW)
}
func (t utxoEventType) IsSpent() bool {
return int(t) == int(pb.UtxoEventType_UTXO_EVENT_TYPE_SPENT)
}
func (t utxoEventType) IsConfirmed() bool {
return int(t) == int(pb.UtxoEventType_UTXO_EVENT_TYPE_CONFIRMED)
}
func (t utxoEventType) IsLocked() bool {
return int(t) == int(pb.UtxoEventType_UTXO_EVENT_TYPE_LOCKED)
}
func (t utxoEventType) IsUnlocked() bool {
return int(t) == int(pb.UtxoEventType_UTXO_EVENT_TYPE_UNLOCKED)
}
type utxoInfo struct {
*pb.Utxo
}
func (i utxoInfo) GetConfirmedStatus() ports.UtxoStatus {
return utxoStatusInfo{i.Utxo.GetConfirmedStatus()}
}
func (i utxoInfo) GetSpentStatus() ports.UtxoStatus {
return utxoStatusInfo{i.Utxo.GetSpentStatus()}
}
type utxoStatusInfo struct {
*pb.UtxoStatus
}
func (i utxoStatusInfo) GetBlockInfo() ports.BlockInfo {
return i.UtxoStatus.GetBlockInfo()
}

View File

@@ -2,20 +2,20 @@ package oceanwallet
import (
"context"
"fmt"
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/ports"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
type service struct {
addr string
conn *grpc.ClientConn
wallet *wallet
account *account
tx *tx
notify *notify
addr string
conn *grpc.ClientConn
walletClient pb.WalletServiceClient
accountClient pb.AccountServiceClient
txClient pb.TransactionServiceClient
}
func NewService(addr string) (ports.WalletService, error) {
@@ -23,37 +23,27 @@ func NewService(addr string) (ports.WalletService, error) {
if err != nil {
return nil, err
}
walletClient := pb.NewWalletServiceClient(conn)
accountClient := pb.NewAccountServiceClient(conn)
txClient := pb.NewTransactionServiceClient(conn)
svc := &service{
addr: addr,
conn: conn,
wallet: newWallet(conn),
account: newAccount(conn),
tx: newTx(conn),
addr: addr,
conn: conn,
walletClient: walletClient,
accountClient: accountClient,
txClient: txClient,
}
if _, err := svc.Wallet().Status(context.Background()); err != nil {
status, err := svc.Status(context.Background())
if err != nil {
return nil, err
}
svc.notify, _ = newNotify(conn)
if !(status.IsInitialized() && status.IsUnlocked()) {
return nil, fmt.Errorf("wallet must be already initialized and unlocked")
}
return svc, nil
}
func (s *service) Wallet() ports.Wallet {
return s.wallet
}
func (s *service) Account() ports.Account {
return s.account
}
func (s *service) Transaction() ports.Transaction {
return s.tx
}
func (s *service) Notification() ports.Notification {
return s.notify
}
func (s *service) Close() {
s.conn.Close()
}

View File

@@ -7,50 +7,14 @@ import (
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/ports"
"github.com/vulpemventures/go-elements/psetv2"
"google.golang.org/grpc"
)
const msatsPerByte = 110
type tx struct {
client pb.TransactionServiceClient
}
func newTx(conn *grpc.ClientConn) *tx {
return &tx{pb.NewTransactionServiceClient(conn)}
}
func (m *tx) GetTransaction(
ctx context.Context, txid string,
) (string, error) {
res, err := m.client.GetTransaction(ctx, &pb.GetTransactionRequest{
Txid: txid,
})
if err != nil {
return "", err
}
return res.GetTxHex(), nil
}
func (m *tx) UpdatePset(
ctx context.Context, pset string,
ins []ports.TxInput, outs []ports.TxOutput,
) (string, error) {
res, err := m.client.UpdatePset(ctx, &pb.UpdatePsetRequest{
Pset: pset,
Inputs: inputList(ins).toProto(),
Outputs: outputList(outs).toProto(),
})
if err != nil {
return "", err
}
return res.GetPset(), nil
}
func (m *tx) SignPset(
func (s *service) SignPset(
ctx context.Context, pset string, extractRawTx bool,
) (string, error) {
res, err := m.client.SignPset(ctx, &pb.SignPsetRequest{
res, err := s.txClient.SignPset(ctx, &pb.SignPsetRequest{
Pset: pset,
})
if err != nil {
@@ -68,10 +32,10 @@ func (m *tx) SignPset(
return ptx.ToBase64()
}
func (m *tx) Transfer(
func (s *service) Transfer(
ctx context.Context, outs []ports.TxOutput,
) (string, error) {
res, err := m.client.Transfer(ctx, &pb.TransferRequest{
res, err := s.txClient.Transfer(ctx, &pb.TransferRequest{
AccountName: accountLabel,
Receivers: outputList(outs).toProto(),
MillisatsPerByte: msatsPerByte,
@@ -82,10 +46,10 @@ func (m *tx) Transfer(
return res.GetTxHex(), nil
}
func (m *tx) BroadcastTransaction(
func (s *service) BroadcastTransaction(
ctx context.Context, txHex string,
) (string, error) {
res, err := m.client.BroadcastTransaction(
res, err := s.txClient.BroadcastTransaction(
ctx, &pb.BroadcastTransactionRequest{
TxHex: txHex,
},
@@ -96,22 +60,6 @@ func (m *tx) BroadcastTransaction(
return res.GetTxid(), nil
}
type inputList []ports.TxInput
func (l inputList) toProto() []*pb.Input {
list := make([]*pb.Input, 0, len(l))
for _, in := range l {
list = append(list, &pb.Input{
Txid: in.GetTxid(),
Index: in.GetIndex(),
Script: in.GetScript(),
ScriptsigSize: uint64(in.GetScriptSigSize()),
WitnessSize: uint64(in.GetWitnessSize()),
})
}
return list
}
type outputList []ports.TxOutput
func (l outputList) toProto() []*pb.Output {

View File

@@ -2,80 +2,42 @@ package oceanwallet
import (
"context"
"strings"
"fmt"
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/ports"
"google.golang.org/grpc"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
const accountLabel = "ark"
type wallet struct {
client pb.WalletServiceClient
accountClient pb.AccountServiceClient
}
func newWallet(conn *grpc.ClientConn) *wallet {
return &wallet{
pb.NewWalletServiceClient(conn),
pb.NewAccountServiceClient(conn),
}
}
func (m *wallet) GenSeed(ctx context.Context) ([]string, error) {
res, err := m.client.GenSeed(ctx, &pb.GenSeedRequest{})
func (s *service) GetPubkey(ctx context.Context) (*secp256k1.PublicKey, error) {
res, err := s.walletClient.GetInfo(ctx, &pb.GetInfoRequest{})
if err != nil {
return nil, err
}
mnemonic := strings.Split(res.GetMnemonic(), " ")
return mnemonic, nil
}
func (m *wallet) InitWallet(
ctx context.Context, mnemonic []string, password string,
) error {
_, err := m.client.CreateWallet(ctx, &pb.CreateWalletRequest{
Mnemonic: strings.Join(mnemonic, " "),
Password: password,
})
return err
}
func (m *wallet) Unlock(ctx context.Context, password string) error {
if _, err := m.client.Unlock(ctx, &pb.UnlockRequest{
Password: password,
}); err != nil {
return err
if len(res.GetAccounts()) <= 0 {
return nil, fmt.Errorf("wallet is locked")
}
// Let's always make sure the 'ark' account is created after unlocking.
info, err := m.client.GetInfo(ctx, &pb.GetInfoRequest{})
xpub := res.GetAccounts()[0].GetXpubs()[0]
node, err := hdkeychain.NewKeyFromString(xpub)
if err != nil {
return err
return nil, err
}
if len(info.GetAccounts()) <= 0 {
_, err := m.accountClient.CreateAccountBIP44(
ctx, &pb.CreateAccountBIP44Request{
Label: accountLabel,
},
)
return err
for i := 0; i < 2; i++ {
node, err = node.Derive(0)
if err != nil {
return nil, err
}
}
return nil
return node.ECPubKey()
}
func (m *wallet) Lock(ctx context.Context, password string) error {
_, err := m.client.Lock(ctx, &pb.LockRequest{
Password: password,
})
return err
}
func (m *wallet) Status(
func (s *service) Status(
ctx context.Context,
) (ports.WalletStatus, error) {
res, err := m.client.Status(ctx, &pb.StatusRequest{})
res, err := s.walletClient.Status(ctx, &pb.StatusRequest{})
if err != nil {
return nil, err
}

View File

@@ -133,7 +133,7 @@ func (b *txBuilder) BuildPoolTx(wallet ports.WalletService, payments []domain.Pa
ctx := context.Background()
return wallet.Transaction().Transfer(ctx, []ports.TxOutput{
return wallet.Transfer(ctx, []ports.TxOutput{
newOutput(aspScript, sharedOutputAmount),
newOutput(aspScript, connectorOutputAmount),
})

View File

@@ -176,6 +176,17 @@ func (h *handler) ListVtxos(ctx context.Context, req *arkv1.ListVtxosRequest) (*
}, nil
}
func (h *handler) GetPubkey(ctx context.Context, req *arkv1.GetPubkeyRequest) (*arkv1.GetPubkeyResponse, error) {
pubkey, err := h.svc.GetPubkey(ctx)
if err != nil {
return nil, err
}
return &arkv1.GetPubkeyResponse{
Pubkey: pubkey,
}, nil
}
func (h *handler) pushListener(l *listener) {
h.listenersLock.Lock()
defer h.listenersLock.Unlock()