Skip to content

Commit

Permalink
Decrease default fees to 0.05 sat/B (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadwahab authored Mar 29, 2023
1 parent ce5d9c0 commit d41610e
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 42 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions examples/create_tx_with_inscription/create_tx_with_inscription.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"
"encoding/hex"
"fmt"
"io/ioutil"
"log"
"mime"

"github.com/libsv/go-bk/wif"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/go-bt/v2/unlocker"
)

func main() {
decodedWif, _ := wif.DecodeWIF("KznpA63DPFrmHecASyL6sFmcRgrNT9oM8Ebso8mwq1dfJF3ZgZ3V")

// get public key bytes and address
pubkey := decodedWif.SerialisePubKey()
addr, _ := bscript.NewAddressFromPublicKeyString(hex.EncodeToString(pubkey), true)
s, _ := bscript.NewP2PKHFromAddress(addr.AddressString)
fmt.Println(addr.AddressString)

tx := bt.NewTx()

_ = tx.From(
"39e5954ee335fdb5a1368ab9e851a954ed513f73f6e8e85eff5e31adbb5837e7",
0,
"76a9144bca0c466925b875875a8e1355698bdcc0b2d45d88ac",
500,
)

// Read the image file
data, err := ioutil.ReadFile("1SatLogoLight.png")
if err != nil {
fmt.Println(err)
return
}

// Get the content type of the image
contentType := mime.TypeByExtension(".png")

tx.Inscribe(&bscript.InscriptionArgs{
LockingScriptPrefix: s,
Data: data,
ContentType: contentType,
})

err = tx.ChangeToAddress("17ujiveRLkf2JQiGR8Sjtwb37evX7vG3WG", bt.NewFeeQuote())
if err != nil {
log.Fatal(err.Error())
}

err = tx.FillAllInputs(context.Background(), &unlocker.Getter{PrivateKey: decodedWif.PrivKey})
if err != nil {
log.Fatal(err.Error())
}

fmt.Println(tx.String())
}
8 changes: 4 additions & 4 deletions fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ func defaultStandardFee() *Fee {
FeeType: FeeTypeStandard,
MiningFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
Bytes: 100,
},
RelayFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
Bytes: 100,
},
}
}
Expand All @@ -310,11 +310,11 @@ func defaultDataFee() *Fee {
FeeType: FeeTypeData,
MiningFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
Bytes: 100,
},
RelayFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
Bytes: 100,
},
}
}
8 changes: 4 additions & 4 deletions fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func TestExtractDataFee(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, FeeTypeData, fee.FeeType)
assert.Equal(t, 5, fee.MiningFee.Satoshis)
assert.Equal(t, 10, fee.MiningFee.Bytes)
assert.Equal(t, 100, fee.MiningFee.Bytes)
assert.Equal(t, 5, fee.RelayFee.Satoshis)
assert.Equal(t, 10, fee.RelayFee.Bytes)
assert.Equal(t, 100, fee.RelayFee.Bytes)
})

t.Run("no data fee found", func(t *testing.T) {
Expand All @@ -40,9 +40,9 @@ func TestExtractStandardFee(t *testing.T) {
assert.NotNil(t, fee)
assert.Equal(t, FeeTypeStandard, fee.FeeType)
assert.Equal(t, 5, fee.MiningFee.Satoshis)
assert.Equal(t, 10, fee.MiningFee.Bytes)
assert.Equal(t, 100, fee.MiningFee.Bytes)
assert.Equal(t, 5, fee.RelayFee.Satoshis)
assert.Equal(t, 10, fee.RelayFee.Bytes)
assert.Equal(t, 100, fee.RelayFee.Bytes)
})

t.Run("no standard fee found", func(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions inscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func TestInscribe(t *testing.T) {
err := tx.Inscribe(test.ia)
assert.NoError(t, err)

fmt.Println(tx.String())

// Check if the transaction has the expected number of outputs
if len(tx.Outputs) != 1 {
t.Fatalf("Inscribe failed: expected 1 output, got %d", len(tx.Outputs))
Expand Down Expand Up @@ -86,7 +84,6 @@ func TestMultipleInscriptionsIn1Tx(t *testing.T) {
pubkey := decodedWif.SerialisePubKey()
addr, _ := bscript.NewAddressFromPublicKeyString(hex.EncodeToString(pubkey), true)
s, _ := bscript.NewP2PKHFromAddress(addr.AddressString)
fmt.Println(addr.AddressString)

tx := NewTx()

Expand Down Expand Up @@ -140,7 +137,6 @@ func TestInscribeFromFile(t *testing.T) {
pubkey := decodedWif.SerialisePubKey()
addr, _ := bscript.NewAddressFromPublicKeyString(hex.EncodeToString(pubkey), true)
s, _ := bscript.NewP2PKHFromAddress(addr.AddressString)
fmt.Println(addr.AddressString)

tx := NewTx()

Expand Down
Loading

0 comments on commit d41610e

Please sign in to comment.