From afda75b35cd5d73588427a4d4698d57b7f64877d Mon Sep 17 00:00:00 2001 From: bruwbird Date: Thu, 2 May 2024 10:45:00 +0900 Subject: [PATCH] wip --- lwk/lwkwallet.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lwk/lwkwallet.go b/lwk/lwkwallet.go index d68476bc..4f78498b 100644 --- a/lwk/lwkwallet.go +++ b/lwk/lwkwallet.go @@ -19,10 +19,10 @@ import ( type Satoshi = uint64 // SatPerKVByte represents a fee rate in sat/kb. -type SatPerKVByte = uint64 +type SatPerKVByte = float64 const ( - minimumSatPerByte = 0.1 + minimumSatPerByte float64 = 0.1 ) // LWKRpcWallet uses the elementsd rpc wallet @@ -109,7 +109,7 @@ func (r *LWKRpcWallet) createWallet(ctx context.Context, walletName, signerName // CreateFundedTransaction takes a tx with outputs and adds inputs in order to spend the tx func (r *LWKRpcWallet) CreateAndBroadcastTransaction(swapParams *swap.OpeningParams, - asset []byte) (txid, rawTx string, fee SatPerKVByte, err error) { + asset []byte) (txid, rawTx string, fee Satoshi, err error) { ctx := context.Background() feerate := float64(r.getFeePerKb(ctx)) fundedTx, err := r.lwkClient.send(ctx, &sendRequest{ @@ -155,7 +155,7 @@ func (r *LWKRpcWallet) CreateAndBroadcastTransaction(swapParams *swap.OpeningPar if err != nil { return "", "", 0, err } - return broadcasted.Txid, txhex, SatPerKVByte(feerate), nil + return broadcasted.Txid, txhex, 0, nil } // GetBalance returns the balance in sats @@ -228,7 +228,7 @@ func (r *LWKRpcWallet) getFeePerKb(ctx context.Context) SatPerKVByte { // convert to sat per byte // 1 kb = 1000 bytes var kb float64 = 1000 - satPerByte := uint64(float64(feeBTCPerKb) * math.Pow10(int(8)) / kb) + satPerByte := float64(feeBTCPerKb) * math.Pow10(int(8)) / kb if satPerByte < minimumSatPerByte { satPerByte = minimumSatPerByte } @@ -241,8 +241,8 @@ func (r *LWKRpcWallet) getFeePerKb(ctx context.Context) SatPerKVByte { func (r *LWKRpcWallet) GetFee(txSize int64) (Satoshi, error) { ctx := context.Background() // assume largest witness - fee := r.getFeePerKb(ctx) * uint64(txSize) - return fee, nil + fee := r.getFeePerKb(ctx) * float64(txSize) + return Satoshi(fee), nil } func (r *LWKRpcWallet) SetLabel(txID, address, label string) error {