Skip to content

Commit

Permalink
Merge pull request #650 from hieblmi/static-addr-2
Browse files Browse the repository at this point in the history
[2/?] Static Loop-In Address - List Unspent
  • Loading branch information
hieblmi authored Mar 11, 2024
2 parents d5cb601 + 23d1915 commit 7ff3318
Show file tree
Hide file tree
Showing 9 changed files with 775 additions and 209 deletions.
48 changes: 48 additions & 0 deletions cmd/loop/staticaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var staticAddressCommands = cli.Command{
Category: "StaticAddress",
Subcommands: []cli.Command{
newStaticAddressCommand,
listUnspentCommand,
},
}

Expand Down Expand Up @@ -57,6 +58,53 @@ func newStaticAddress(ctx *cli.Context) error {
return nil
}

var listUnspentCommand = cli.Command{
Name: "listunspent",
ShortName: "l",
Usage: "List unspent static address outputs.",
Description: `
List all unspent static address outputs.
`,
Flags: []cli.Flag{
cli.IntFlag{
Name: "min_confs",
Usage: "The minimum amount of confirmations an " +
"output should have to be listed.",
},
cli.IntFlag{
Name: "max_confs",
Usage: "The maximum number of confirmations an " +
"output could have to be listed.",
},
},
Action: listUnspent,
}

func listUnspent(ctx *cli.Context) error {
ctxb := context.Background()
if ctx.NArg() > 0 {
return cli.ShowCommandHelp(ctx, "listunspent")
}

client, cleanup, err := getAddressClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.ListUnspent(ctxb, &looprpc.ListUnspentRequest{
MinConfs: int32(ctx.Int("min_confs")),
MaxConfs: int32(ctx.Int("max_confs")),
})
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

func getAddressClient(ctx *cli.Context) (looprpc.StaticAddressClientClient,
func(), error) {

Expand Down
7 changes: 7 additions & 0 deletions loopd/perms/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ var RequiredPermissions = map[string][]bakery.Op{
Entity: "loop",
Action: "in",
}},
"/looprpc.StaticAddressClient/ListUnspent": {{
Entity: "swap",
Action: "read",
}, {
Entity: "loop",
Action: "in",
}},
"/looprpc.SwapClient/GetLsatTokens": {{
Entity: "auth",
Action: "read",
Expand Down
678 changes: 471 additions & 207 deletions looprpc/client.pb.go

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions looprpc/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,10 @@ service StaticAddressClient {
NewAddress requests a new static address for loop-ins from the server.
*/
rpc NewAddress (NewAddressRequest) returns (NewAddressResponse);
/*
ListUnspent returns a list of utxos behind a static address.
*/
rpc ListUnspent (ListUnspentRequest) returns (ListUnspentResponse);
}

message NewAddressRequest {
Expand All @@ -1406,4 +1410,51 @@ message NewAddressResponse {
The taproot static address.
*/
string address = 1;

/*
The CSV expiry of the static address.
*/
uint32 expiry = 2;
}

message ListUnspentRequest {
/*
The number of minimum confirmations a utxo must have to be listed.
*/
int32 min_confs = 1;

/*
The number of maximum confirmations a utxo may have to be listed. A zero
value indicates that there is no maximum.
*/
int32 max_confs = 2;
}

message ListUnspentResponse {
/*
A list of utxos behind the static address.
*/
repeated Utxo utxos = 1;
}

message Utxo {
/*
The static address of the utxo.
*/
string static_address = 1;

/*
The value of the unspent coin in satoshis.
*/
int64 amount_sat = 2;

/*
The outpoint in the form txid:index.
*/
string outpoint = 3;

/*
The number of confirmations for the Utxo.
*/
int64 confirmations = 4;
}
40 changes: 40 additions & 0 deletions looprpc/client.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,18 @@
}
}
},
"looprpcListUnspentResponse": {
"type": "object",
"properties": {
"utxos": {
"type": "array",
"items": {
"$ref": "#/definitions/looprpcUtxo"
},
"description": "A list of utxos behind the static address."
}
}
},
"looprpcLoopInRequest": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1244,6 +1256,11 @@
"address": {
"type": "string",
"description": "The taproot static address."
},
"expiry": {
"type": "integer",
"format": "int64",
"description": "The CSV expiry of the static address."
}
}
},
Expand Down Expand Up @@ -1509,6 +1526,29 @@
}
}
},
"looprpcUtxo": {
"type": "object",
"properties": {
"static_address": {
"type": "string",
"description": "The static address of the utxo."
},
"amount_sat": {
"type": "string",
"format": "int64",
"description": "The value of the unspent coin in satoshis."
},
"outpoint": {
"type": "string",
"description": "The outpoint in the form txid:index."
},
"confirmations": {
"type": "string",
"format": "int64",
"description": "The number of confirmations for the Utxo."
}
}
},
"protobufAny": {
"type": "object",
"properties": {
Expand Down
40 changes: 40 additions & 0 deletions looprpc/client_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions looprpc/staticaddressclient.pb.json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ff3318

Please sign in to comment.