-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from hieblmi/static-addr-1
[1/?] Static Loop-In Address - Create
- Loading branch information
Showing
28 changed files
with
1,834 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/lightninglabs/loop/looprpc" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var staticAddressCommands = cli.Command{ | ||
Name: "static", | ||
ShortName: "s", | ||
Usage: "manage static loop-in addresses", | ||
Category: "StaticAddress", | ||
Subcommands: []cli.Command{ | ||
newStaticAddressCommand, | ||
}, | ||
} | ||
|
||
var newStaticAddressCommand = cli.Command{ | ||
Name: "new", | ||
ShortName: "n", | ||
Usage: "Create a new static loop in address.", | ||
Description: ` | ||
Requests a new static loop in address from the server. Funds that are | ||
sent to this address will be locked by a 2:2 multisig between us and the | ||
loop server, or a timeout path that we can sweep once it opens up. The | ||
funds can either be cooperatively spent with a signature from the server | ||
or looped in. | ||
`, | ||
Action: newStaticAddress, | ||
} | ||
|
||
func newStaticAddress(ctx *cli.Context) error { | ||
ctxb := context.Background() | ||
if ctx.NArg() > 0 { | ||
return cli.ShowCommandHelp(ctx, "new") | ||
} | ||
|
||
client, cleanup, err := getAddressClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer cleanup() | ||
|
||
resp, err := client.NewAddress( | ||
ctxb, &looprpc.NewAddressRequest{}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Received a new static loop-in address from the server: "+ | ||
"%s\n", resp.Address) | ||
|
||
return nil | ||
} | ||
|
||
func getAddressClient(ctx *cli.Context) (looprpc.StaticAddressClientClient, | ||
func(), error) { | ||
|
||
rpcServer := ctx.GlobalString("rpcserver") | ||
tlsCertPath, macaroonPath, err := extractPathArgs(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
cleanup := func() { conn.Close() } | ||
|
||
addressClient := looprpc.NewStaticAddressClientClient(conn) | ||
return addressClient, cleanup, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS static_addresses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- static_address stores the static loop-in addresses that clients | ||
-- cooperatively created with the server. | ||
CREATE TABLE IF NOT EXISTS static_addresses ( | ||
-- id is the auto-incrementing primary key for a static address. | ||
id INTEGER PRIMARY KEY, | ||
|
||
-- client_pubkey is the client side public taproot key that is used to | ||
-- construct the 2-of-2 MuSig2 taproot output that represents the static | ||
-- address. | ||
client_pubkey BYTEA NOT NULL, | ||
|
||
-- server_pubkey is the server side public taproot key that is used to | ||
-- construct the 2-of-2 MuSig2 taproot output that represents the static | ||
-- address. | ||
server_pubkey BYTEA NOT NULL, | ||
|
||
-- expiry denotes the CSV delay at which funds at a specific static address | ||
-- can be swept back to the client. | ||
expiry INT NOT NULL, | ||
|
||
-- client_key_family is the key family of the client public key from the | ||
-- client's lnd wallet. | ||
client_key_family INT NOT NULL, | ||
|
||
-- client_key_index is the key index of the client public key from the | ||
-- client's lnd wallet. | ||
client_key_index INT NOT NULL, | ||
|
||
-- pkscript is the witness program that represents the static address. It is | ||
-- unique amongst all static addresses. | ||
pkscript BYTEA NOT NULL UNIQUE, | ||
|
||
-- protocol_version is the protocol version that the swap was created with. | ||
-- Note that this version is not upgraded if the client upgrades or | ||
-- downgrades their protocol version for static address outputs already in | ||
-- use. | ||
protocol_version INTEGER NOT NULL | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- name: AllStaticAddresses :many | ||
SELECT * FROM static_addresses; | ||
|
||
-- name: GetStaticAddress :one | ||
SELECT * FROM static_addresses | ||
WHERE pkscript=$1; | ||
|
||
-- name: CreateStaticAddress :exec | ||
INSERT INTO static_addresses ( | ||
client_pubkey, | ||
server_pubkey, | ||
expiry, | ||
client_key_family, | ||
client_key_index, | ||
pkscript, | ||
protocol_version | ||
) VALUES ( | ||
$1, | ||
$2, | ||
$3, | ||
$4, | ||
$5, | ||
$6, | ||
$7 | ||
); |
Oops, something went wrong.