Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/?] Static Loop-In Address - List Unspent #650

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for max_confs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The m.cfg.WalletKit.ListUnspent method takes maxConfs as argument which is what ListUnspentRaw will call, so I want the user to be able to use that.
E.g. if you know that the CSV on your static address is 1000, I could see with maxConf=900 which utxos expire in 100 or more blocks...

}

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
Loading