Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,34 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.22", "1.23"]
go: ['1.23', '1.24']
steps:
- name: Check out source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 #v5.3.0
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ matrix.go }}
- name: Use lint cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2.0
cache: true # enables automatic go.mod/go.sum caching
cache-dependency-path: go.sum

- name: Cache golangci-lint
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/.cache/golangci-lint
key: golangci-lint-${{ matrix.go }}-${{ hashFiles('go.sum') }}
restore-keys: |
golangci-lint-${{ matrix.go }}-

- name: Install golangci-lint
uses: golangci/golangci-lint-action@v9 # Latest stable (v9.0.0)
with:
path: |
~/.cache/golangci-lint
key: go-lint-${{ matrix.go }}-${{ hashFiles('./go.sum') }}
restore-keys: go-lint-${{ matrix.go }}
- name: Install Linters
run: "go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2"
args: --timeout=10m # optional

- name: Build
run: go build ./...
run: go build -v ./...

- name: Test
run: |
sh ./run_tests.sh
run: sh ./run_tests.sh

9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
go.work
go.work.sum

# go mod tidy all
gmt.sh

#test bin
cmd/goele-btc/goele-btc
cmd/mkwallet-btc/mkwallet-btc
cmd/rmwallet-btc/rmwallet-btc
cmd/goele-firo/goele-firo
cmd/mkwallet-firo/mkwallet-firo
cmd/rmwallet-firo/rmwallet-firo
cmd/goele-dash/goele-btc
cmd/mkwallet-dash/mkwallet-btc
cmd/rmwallet-dash/rmwallet-btc
cmd/goele-dash/goele-dash
cmd/mkwallet-dash/mkwallet-dash
cmd/rmwallet-dash/rmwallet-dash
wallet/cmd/boltdmp/bd
wallet/cmd/boltdmp/boltdmp
client/btc/rpc_test/client
Expand Down
76 changes: 55 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
# MIT License

Copyright (c) 2023,2025 dev-warrior777

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Blue Oak Model License

Version 1.0.0

## Purpose

This license gives everyone as much permission to work with
this software as possible, while protecting contributors
from liability.

## Acceptance

In order to receive this license, you must agree to its
rules. The rules of this license are both obligations
under that agreement and conditions to your license.
You must not do anything with this software that triggers
a rule that you cannot or will not follow.

## Copyright

Each contributor licenses you to do everything with this
software that would otherwise infringe that contributor's
copyright in it.

## Notices

You must ensure that everyone who gets a copy of
any part of this software from you, with or without
changes, also gets the text of this license or a link to
<https://blueoakcouncil.org/license/1.0.0>.

## Excuse

If anyone notifies you in writing that you have not
complied with [Notices](#notices), you can keep your
license by taking all practical steps to comply within 30
days after the notice. If you do not do so, your license
ends immediately.

## Patent

Each contributor licenses you to do everything with this
software that would otherwise infringe any patent claims
they can license or become able to license.

## Reliability

No contributor can revoke this license.

## No Liability

***As far as the law allows, this software comes as is,
without any warranty or condition, and no contributor
will be liable to anyone for any damages related to this
software or this license, under any kind of legal claim.***
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ __Goele__ - Golang Electrum Client

## Development example

The __goele__ example app can be found at `cmd/goele-btc/`. This is the tool I have been using for functional testing.
The __goele__ example app can be found at `cmd/goele-<coin-name>/` [btc,dash,firo]. These tools can be used for functional testing.

If running against regtest network then it is dependent upon the _BTC ElectrumX RegTest Simnet Harness_ found in `client/btc/test_harness`.

Expand Down
3 changes: 3 additions & 0 deletions client/btc/blockchain.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
Expand Down
22 changes: 20 additions & 2 deletions client/btc/client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
"context"
"errors"
"fmt"
"os"
"path"
"sync"

"decred.org/dcrdex/dex"
"github.com/bisoncraft/go-electrum-client/client"
"github.com/bisoncraft/go-electrum-client/electrumx"
"github.com/bisoncraft/go-electrum-client/electrumx/elxbtc"
Expand All @@ -20,6 +25,8 @@ import (
type BtcElectrumClient struct {
// Cancel is the cancel func for the goele context
Cancel context.CancelFunc
// Log is a dex logger
Log dex.Logger
// The Goele configuration
ClientConfig *client.ClientConfig
// Goele wallet
Expand All @@ -36,6 +43,7 @@ type BtcElectrumClient struct {
func NewBtcElectrumClient(cfg *client.ClientConfig) client.ElectrumClient {
ec := BtcElectrumClient{
Cancel: nil,
Log: nil,
ClientConfig: cfg,
Wallet: nil,
X: nil,
Expand Down Expand Up @@ -115,14 +123,23 @@ func (ec *BtcElectrumClient) createElectrumXInterface() error {

// client interface implementation

func (ec *BtcElectrumClient) Start(parentCtx context.Context) error {
func (ec *BtcElectrumClient) Start(parentCtx context.Context, logger dex.Logger) error {
if parentCtx == nil {
return fmt.Errorf("context from caller is nil")
}
if logger == nil {
return fmt.Errorf("dex logger from caller is nil")
}
goeleCtx, goeleCancel := context.WithCancel(parentCtx)
ec.Cancel = goeleCancel
ec.Log = logger.SubLogger("GOEL").SubLogger("btc")
ec.Log.Infof("starting electrum client")
err := ec.createElectrumXInterface()
if err != nil {
return err
}
err = ec.X.Start(goeleCtx)
ec.Log.Debug("starting electrumX interface")
err = ec.X.Start(goeleCtx, ec.Log)
if err != nil {
return err
}
Expand All @@ -131,6 +148,7 @@ func (ec *BtcElectrumClient) Start(parentCtx context.Context) error {
return err
}
go ec.tipChange(goeleCtx)
ec.Log.Info("electrum client started")
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions client/btc/client_node.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
Expand Down
3 changes: 3 additions & 0 deletions client/btc/client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
Expand Down
7 changes: 5 additions & 2 deletions client/btc/client_wallet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
Expand Down Expand Up @@ -46,7 +49,7 @@ func (ec *BtcElectrumClient) SyncWallet(ctx context.Context) error {
return err
}
if status == "" {
// fmt.Println("no history for this script address .. yet")
ec.Log.Trace("no history for this script address .. yet")
continue
}
// get address history to date for this address from ElectrumX
Expand Down Expand Up @@ -240,7 +243,7 @@ func (ec *BtcElectrumClient) Broadcast(ctx context.Context, rawTx []byte) (strin
backToWallet[idx] = pkScript
}
}
// fmt.Printf("found %d address(es) back to our wallet\n", len(backToWallet))
ec.Log.Tracef("found %d address(es) back to our wallet\n", len(backToWallet))

// Send tx to ElectrumX for broadcasting to the bitcoin network
rawTxStr := hex.EncodeToString(rawTx)
Expand Down
7 changes: 5 additions & 2 deletions client/btc/import_sweep.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
Expand Down Expand Up @@ -153,13 +156,13 @@ func (ec *BtcElectrumClient) ImportAndSweep(ctx context.Context, importedKeyPair
for _, k := range importedKeyPairs {
wif, err := btcutil.DecodeWIF(k)
if err != nil {
fmt.Printf("warning cannot decode WIF from string: %s\n", k)
ec.Log.Warnf("warning cannot decode WIF from string: %s", k)
continue
}

inputsForKey, err := ec.getUtxos(ctx, wif)
if err != nil {
fmt.Printf("warning cannot get utxos for pubkey: %s\n",
ec.Log.Warnf("warning cannot get utxos for pubkey: %s",
hex.EncodeToString(wif.SerializePubKey()))
continue
}
Expand Down
24 changes: 13 additions & 11 deletions client/btc/rescan.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package btc

import (
"context"
"encoding/hex"
"fmt"

"github.com/bisoncraft/go-electrum-client/client"
"github.com/bisoncraft/go-electrum-client/wallet"
Expand Down Expand Up @@ -35,23 +37,23 @@ func (ec *BtcElectrumClient) RescanWallet(ctx context.Context) error {
}
address, err := w.GetAddress(keyPath)
if err != nil {
fmt.Printf("bad address for: %d:%d\n", keyIndex, change)
ec.Log.Errorf("bad address for: %d:%d - %v", keyIndex, change, err)
continue
}
scripthash, err := addressToElectrumScripthash(address)
if err != nil {
fmt.Printf("cannot make script hash for address: %s\n", address.String())
ec.Log.Errorf("cannot make script hash for address: %s - %v", address.String(), err)
continue
}
// fmt.Printf("%s %s Index:change %d:%d\n", address.String(), scripthash, keyIndex, change)
ec.Log.Tracef("%s %s Index:change %d:%d", address.String(), scripthash, keyIndex, change)

history, err := node.GetHistory(ctx, scripthash)
if err != nil {
fmt.Printf("error: %v - for scripthash %s\n", scripthash, err)
ec.Log.Errorf("error: %v - for scripthash %s", scripthash, err)
continue
}
if len(history) == 0 {
// fmt.Printf("No history for script hash from node: %s\n", scripthash)
ec.Log.Tracef("No history for script hash from node: %s", scripthash)
continue
}
// got history - update the highest hit index
Expand All @@ -63,7 +65,7 @@ func (ec *BtcElectrumClient) RescanWallet(ctx context.Context) error {
// }
pkScriptBytes, err := w.AddressToScript(address)
if err != nil {
fmt.Printf("cannot make pkScript for address: %s\n", address.String())
ec.Log.Errorf("cannot make pkScript for address: %s - %v", address.String(), err)
continue
}
subscription := &wallet.Subscription{
Expand All @@ -73,17 +75,17 @@ func (ec *BtcElectrumClient) RescanWallet(ctx context.Context) error {
}
err = w.AddSubscription(subscription)
if err != nil {
fmt.Printf("cannot add subscritpion for address: %s\n", address.String())
ec.Log.Errorf("cannot add subscritpion for address: %s - %v", address.String(), err)
// ec.dumpSubscription("failed to add", subscription)
continue
}
// fmt.Printf("Added subscritpion for address: %s to wallet subscriptions\n", address.String())
ec.Log.Tracef("Added subscription for address: %s to wallet subscriptions", address.String())
}

// if no more history hits for another GAP_LIMIT tries consider the job done.
if keyIndex > historyHitIndex+client.GAP_LIMIT {
// fmt.Printf("keyIndex: %d greater than highest history found index %d by GAP_LIMIT %d\n\n",
// keyIndex, historyHitIndex, client.GAP_LIMIT)
ec.Log.Debugf("keyIndex: %d greater than highest history found index %d by GAP_LIMIT %d",
keyIndex, historyHitIndex, client.GAP_LIMIT)
break
}
}
Expand Down
3 changes: 3 additions & 0 deletions client/btc/rpc_test/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package main

import (
Expand Down
6 changes: 4 additions & 2 deletions client/btc/rpc_test/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/bisoncraft/go-electrum-client/client/btc/rpc_test

go 1.19
go 1.23.0

require github.com/spf13/cast v1.7.1
toolchain go1.24.4

require github.com/spf13/cast v1.10.0
Loading
Loading