当前位置: 首页>>代码示例>>Golang>>正文


Golang LightningWallet.ActiveReservations方法代码示例

本文整理汇总了Golang中github.com/lightningnetwork/lnd/lnwallet.LightningWallet.ActiveReservations方法的典型用法代码示例。如果您正苦于以下问题:Golang LightningWallet.ActiveReservations方法的具体用法?Golang LightningWallet.ActiveReservations怎么用?Golang LightningWallet.ActiveReservations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/lightningnetwork/lnd/lnwallet.LightningWallet的用法示例。


在下文中一共展示了LightningWallet.ActiveReservations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testFundingCancellationNotEnoughFunds

func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
	wallet *lnwallet.LightningWallet, t *testing.T) {

	t.Log("Running funding insufficient funds tests")

	// Create a reservation for 44 BTC.
	fundingAmount := btcutil.Amount(44 * 1e8)
	chanReservation, err := wallet.InitChannelReservation(fundingAmount,
		fundingAmount, testPub, bobAddr, numReqConfs, 4)
	if err != nil {
		t.Fatalf("unable to initialize funding reservation: %v", err)
	}

	// Attempt to create another channel with 44 BTC, this should fail.
	_, err = wallet.InitChannelReservation(fundingAmount,
		fundingAmount, testPub, bobAddr, numReqConfs, 4)
	if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
		t.Fatalf("coin selection succeded should have insufficient funds: %v",
			err)
	}

	// Now cancel that old reservation.
	if err := chanReservation.Cancel(); err != nil {
		t.Fatalf("unable to cancel reservation: %v", err)
	}

	// Those outpoints should no longer be locked.
	lockedOutPoints := wallet.LockedOutpoints()
	if len(lockedOutPoints) != 0 {
		t.Fatalf("outpoints still locked")
	}

	// Reservation ID should no longer be tracked.
	numReservations := wallet.ActiveReservations()
	if len(wallet.ActiveReservations()) != 0 {
		t.Fatalf("should have 0 reservations, instead have %v",
			numReservations)
	}

	// TODO(roasbeef): create method like Balance that ignores locked
	// outpoints, will let us fail early/fast instead of querying and
	// attempting coin selection.

	// Request to fund a new channel should now succeeed.
	_, err = wallet.InitChannelReservation(fundingAmount, fundingAmount,
		testPub, bobAddr, numReqConfs, 4)
	if err != nil {
		t.Fatalf("unable to initialize funding reservation: %v", err)
	}
}
开发者ID:lightningnetwork,项目名称:lnd,代码行数:50,代码来源:interface_test.go


注:本文中的github.com/lightningnetwork/lnd/lnwallet.LightningWallet.ActiveReservations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。