Skip to content

Commit

Permalink
fixup: refactor the code
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedawnallah committed Mar 6, 2024
1 parent e0c07c5 commit cd85404
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 192 deletions.
4 changes: 2 additions & 2 deletions cmd/lncli/cmd_open_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ var batchOpenChannelCommand = cli.Command{
"wallet after publishing it",
},
cli.StringFlag{
Name: "coin_selection_strategy",
Name: "coin_selection_strategy",
Usage: "(optional) The strategy to use for selecting " +
"coins to fund the transactions for opening " +
"the channels. If provided, it will " +
Expand Down Expand Up @@ -854,7 +854,7 @@ func batchOpenChannel(ctx *cli.Context) error {
return nil
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func estimateFees(ctx *cli.Context) error {
return err
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand All @@ -248,8 +248,8 @@ func estimateFees(ctx *cli.Context) error {
defer cleanUp()

resp, err := client.EstimateFee(ctxc, &lnrpc.EstimateFeeRequest{
AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")),
AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")),
CoinSelectionStrategy: *coinSelectionStrategy,
})
if err != nil {
Expand Down Expand Up @@ -328,7 +328,7 @@ var sendCoinsCommand = cli.Command{
"scripts",
},
cli.StringFlag{
Name: "coin_selection_strategy",
Name: "coin_selection_strategy",
Usage: "(optional) the strategy to use for selecting " +
"coins to send bitcoin on-chain " +
"to an address. If provided, it will " +
Expand Down Expand Up @@ -398,7 +398,7 @@ func sendCoins(ctx *cli.Context) error {
"sweep all coins out of the wallet")
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand Down Expand Up @@ -617,7 +617,7 @@ var sendManyCommand = cli.Command{
Value: defaultUtxoMinConf,
},
cli.StringFlag{
Name: "coin_selection_strategy",
Name: "coin_selection_strategy",
Usage: "(optional) the strategy to use for selecting " +
"coins to send bitcoin on-chain " +
"to multiple addresses. If provided, it will " +
Expand Down Expand Up @@ -655,7 +655,7 @@ func sendMany(ctx *cli.Context) error {
return err
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ var fundTemplatePsbtCommand = cli.Command{
Value: -1,
},
cli.StringFlag{
Name: "coin_selection_strategy",
Name: "coin_selection_strategy",
Usage: "(optional) the strategy to use for selecting " +
"coins to fund the PSBT from a template. " +
"If provided it will override the globally " +
Expand Down Expand Up @@ -1004,7 +1004,7 @@ func fundTemplatePsbt(ctx *cli.Context) error {
"inputs/outputs flag")
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand Down Expand Up @@ -1183,7 +1183,7 @@ var fundPsbtCommand = cli.Command{
Value: defaultUtxoMinConf,
},
cli.StringFlag{
Name: "coin_selection_strategy",
Name: "coin_selection_strategy",
Usage: "(optional) the strategy to use for selecting " +
"coins to fund the PSBT. If provided, it " +
"will override the globally configured " +
Expand All @@ -1203,7 +1203,7 @@ func fundPsbt(ctx *cli.Context) error {
return cli.ShowCommandHelp(ctx, "fund")
}

coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategyString(
coinSelectionStrategy, err := lnrpc.ParseCoinSelectionStrategy(
ctx.String("coin_selection_strategy"),
)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions funding/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,10 @@ func TestBatchFund(t *testing.T) {
tc.failPublish,
)

strategy := lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST
req := &lnrpc.BatchOpenChannelRequest{
Channels: tc.channels,
SatPerVbyte: 5,
MinConfs: 1,
CoinSelectionStrategy: strategy,
Channels: tc.channels,
SatPerVbyte: 5,
MinConfs: 1,
}
updates, err := h.batcher.BatchFund(
context.Background(), req,
Expand Down
1 change: 0 additions & 1 deletion itest/lnd_channel_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,6 @@ func createLegacyRevocationChannel(ht *lntest.HarnessTest,
Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{
SatPerVbyte: 2,
},
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
}
fundResp := from.RPC.FundPsbt(fundReq)

Expand Down
5 changes: 2 additions & 3 deletions itest/lnd_channel_funding_fund_max_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ func sweepNodeWalletAndAssert(ht *lntest.HarnessTest, node *node.HarnessNode) {

// Send all funds back to the miner node.
node.RPC.SendCoins(&lnrpc.SendCoinsRequest{
Addr: minerAddr.String(),
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: minerAddr.String(),
SendAll: true,
})

// Ensures we don't leave any transaction in the mempool after sweeping.
Expand Down
6 changes: 2 additions & 4 deletions itest/lnd_funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,8 @@ func sendAllCoinsConfirm(ht *lntest.HarnessTest, node *node.HarnessNode,
addr string) {

sweepReq := &lnrpc.SendCoinsRequest{
Addr: addr,
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: addr,
SendAll: true,
}
node.RPC.SendCoins(sweepReq)
ht.MineBlocksAndAssertNumTxes(1, 1)
Expand Down Expand Up @@ -983,7 +982,6 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
ZeroConf: true,
CommitmentType: lnrpc.CommitmentType_ANCHORS,
}},
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
}

// Check that batch opening fails due to the minchansize requirement.
Expand Down
56 changes: 24 additions & 32 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,18 +777,16 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {

// Ensure that we can't send coins to our own Pubkey.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ainz.RPC.GetInfo().IdentityPubkey,
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: ainz.RPC.GetInfo().IdentityPubkey,
SendAll: true,
Label: sendCoinsLabel,
})

// Ensure that we can't send coins to another user's Pubkey.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ht.Alice.RPC.GetInfo().IdentityPubkey,
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: ht.Alice.RPC.GetInfo().IdentityPubkey,
SendAll: true,
Label: sendCoinsLabel,
})

// With the two coins above mined, we'll now instruct Ainz to sweep all
Expand All @@ -800,26 +798,23 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {

// Send coins to a testnet3 address.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
SendAll: true,
Label: sendCoinsLabel,
})

// Send coins to a mainnet address.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3",
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3",
SendAll: true,
Label: sendCoinsLabel,
})

// Send coins to a compatible address.
ainz.RPC.SendCoins(&lnrpc.SendCoinsRequest{
Addr: ht.Miner.NewMinerAddress().String(),
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: ht.Miner.NewMinerAddress().String(),
SendAll: true,
Label: sendCoinsLabel,
})

// We'll mine a block which should include the sweep transaction we
Expand Down Expand Up @@ -916,11 +911,10 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// If we try again, but this time specifying an amount, then the call
// should fail.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ht.Miner.NewMinerAddress().String(),
Amount: 10000,
SendAll: true,
Label: sendCoinsLabel,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: ht.Miner.NewMinerAddress().String(),
Amount: 10000,
SendAll: true,
Label: sendCoinsLabel,
})

// With all the edge cases tested, we'll now test the happy paths of
Expand All @@ -946,9 +940,8 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// Let's send some coins to the main address.
const amt = 123456
resp := ainz.RPC.SendCoins(&lnrpc.SendCoinsRequest{
Addr: mainAddrResp.Address,
Amount: amt,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: mainAddrResp.Address,
Amount: amt,
})
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
sweepTx := block.Transactions[1]
Expand Down Expand Up @@ -1028,10 +1021,9 @@ func testListAddresses(ht *lntest.HarnessTest) {

for addr, addressDetail := range generatedAddr {
alice.RPC.SendCoins(&lnrpc.SendCoinsRequest{
Addr: addr,
Amount: addressDetail.Balance,
SpendUnconfirmed: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: addr,
Amount: addressDetail.Balance,
SpendUnconfirmed: true,
})
}

Expand Down
7 changes: 3 additions & 4 deletions itest/lnd_nonstd_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {
// Make Carol call SendCoins with the SendAll flag and the created
// address.
sendReq := &lnrpc.SendCoinsRequest{
Addr: address,
SatPerVbyte: 1,
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: address,
SatPerVbyte: 1,
SendAll: true,
}

// If a non-standard transaction was created, then this SendCoins call
Expand Down
44 changes: 18 additions & 26 deletions itest/lnd_onchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ func testChainKitSendOutputsAnchorReserve(ht *lntest.HarnessTest) {
Value: utxo.Value,
PkScript: utxo.PkScript,
}},
SatPerKw: 2400,
MinConfs: 1,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
SatPerKw: 2400,
MinConfs: 1,
}

// We try to send the reserve violating transaction and expect it to
Expand All @@ -198,9 +197,8 @@ func testChainKitSendOutputsAnchorReserve(ht *lntest.HarnessTest) {
Value: utxo.Value,
PkScript: utxo.PkScript,
}},
SatPerKw: 2400,
MinConfs: 1,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
SatPerKw: 2400,
MinConfs: 1,
}

// This second transaction should be published correctly.
Expand Down Expand Up @@ -242,9 +240,8 @@ func runCPFP(ht *lntest.HarnessTest, alice, bob *node.HarnessNode) {
// Send the coins from Alice to Bob. We should expect a transaction to
// be broadcast and seen in the mempool.
sendReq := &lnrpc.SendCoinsRequest{
Addr: resp.Address,
Amount: btcutil.SatoshiPerBitcoin,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: resp.Address,
Amount: btcutil.SatoshiPerBitcoin,
}
alice.RPC.SendCoins(sendReq)
txid := ht.Miner.AssertNumTxsInMempool(1)[0]
Expand Down Expand Up @@ -386,9 +383,8 @@ func testAnchorReservedValue(ht *lntest.HarnessTest) {
resp := alice.RPC.NewAddress(req)

sweepReq := &lnrpc.SendCoinsRequest{
Addr: resp.Address,
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: resp.Address,
SendAll: true,
}
alice.RPC.SendCoins(sweepReq)

Expand Down Expand Up @@ -436,9 +432,8 @@ func testAnchorReservedValue(ht *lntest.HarnessTest) {
minerAddr := ht.Miner.NewMinerAddress()

sweepReq = &lnrpc.SendCoinsRequest{
Addr: minerAddr.String(),
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: minerAddr.String(),
SendAll: true,
}
alice.RPC.SendCoins(sweepReq)

Expand Down Expand Up @@ -474,9 +469,8 @@ func testAnchorReservedValue(ht *lntest.HarnessTest) {
// We'll wait for the balance to reflect that the channel has been
// closed and the funds are in the wallet.
sweepReq = &lnrpc.SendCoinsRequest{
Addr: minerAddr.String(),
SendAll: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: minerAddr.String(),
SendAll: true,
}
alice.RPC.SendCoins(sweepReq)

Expand Down Expand Up @@ -606,11 +600,10 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
// (to the miner), including unconfirmed change.
minerAddr := ht.Miner.NewMinerAddress()
sweepReq := &lnrpc.SendCoinsRequest{
Addr: minerAddr.String(),
SendAll: true,
MinConfs: 0,
SpendUnconfirmed: true,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: minerAddr.String(),
SendAll: true,
MinConfs: 0,
SpendUnconfirmed: true,
}
sweepAllResp := alice.RPC.SendCoins(sweepReq)

Expand Down Expand Up @@ -762,9 +755,8 @@ func testRemoveTx(ht *lntest.HarnessTest) {
// We send half the amount to that address generating two unconfirmed
// outpoints in our internal wallet.
sendReq := &lnrpc.SendCoinsRequest{
Addr: resp.Address,
Amount: initialWalletAmt / 2,
CoinSelectionStrategy: lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST,
Addr: resp.Address,
Amount: initialWalletAmt / 2,
}
alice.RPC.SendCoins(sendReq)
txID := ht.Miner.AssertNumTxsInMempool(1)[0]
Expand Down

0 comments on commit cd85404

Please sign in to comment.