Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Remote Wallet Support #68

Open
wants to merge 66 commits into
base: testnet4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
17bb45c
Fixex #66
May 16, 2024
2497988
May 16, 2024
dd60b37
May 24, 2024
96f853b
May 24, 2024
2709348
Jun 10, 2024
bf1ac9c
Jun 10, 2024
aabea7b
merge commit
Jun 18, 2024
d46ab26
Jun 19, 2024
4ea7e6f
Jun 19, 2024
a25f3bd
Jun 19, 2024
6ec2724
Jun 19, 2024
82ebb06
Jun 20, 2024
b37fe51
Jun 20, 2024
bb2cf1b
Jun 20, 2024
6a34592
Jun 23, 2024
90d7314
Jun 23, 2024
014563a
Jun 29, 2024
1e69996
Jun 29, 2024
7ec17a5
Jun 29, 2024
d222006
Jun 29, 2024
61a3fdd
Jul 7, 2024
d52ce43
Jul 11, 2024
41e7ee9
Jul 11, 2024
05940e2
Jul 17, 2024
a611633
Jul 26, 2024
762736e
Jul 26, 2024
c21de60
Jul 26, 2024
c0e7f9f
Jul 26, 2024
0973d1b
Jul 26, 2024
f50d47c
Jul 26, 2024
2f372f9
Jul 26, 2024
c8e7468
Jul 26, 2024
4b4dc6c
Jul 26, 2024
5ab4175
Jul 27, 2024
c030d24
Jul 27, 2024
91d7962
Jul 27, 2024
4f9c30e
Jul 27, 2024
d907016
Jul 28, 2024
ca24470
Jul 31, 2024
be9c93e
Aug 13, 2024
9444fe4
Aug 13, 2024
15b9ce2
Aug 13, 2024
9e1b588
Aug 13, 2024
68f2013
Aug 13, 2024
904a195
Aug 28, 2024
60a8a6b
Aug 28, 2024
727e5af
feat: Add support for remote wallet
humblenginr Jul 3, 2024
cade0b0
chore: Add documentation
humblenginr Jul 4, 2024
a502a7d
refactor: Change client and server
humblenginr Jul 4, 2024
b08458b
make sign transaction a button and respsect user confirmation
humblenginr Jul 5, 2024
1754112
feat: Add error handling
humblenginr Jul 11, 2024
9212da5
feat:realtime connection status update
humblenginr Jul 11, 2024
7f02b57
refactor: Rename client to gateway
humblenginr Aug 27, 2024
bb0103b
refactor: Add config support
humblenginr Aug 27, 2024
8600889
refactor: Add SSE to make signing asynchronous with prompt
humblenginr Aug 31, 2024
12a0867
refactor: delegate signing to wallet
humblenginr Sep 2, 2024
8d97a81
fix: proper cleanup of websocket connection
humblenginr Sep 2, 2024
e28a197
fix: remove fixed wallet paths
humblenginr Sep 2, 2024
7fd8ff1
refactor: change ws addr, remove wallet fixed path need
humblenginr Sep 3, 2024
37905da
fix: Remove gateway binary
humblenginr Sep 3, 2024
8664f78
fix: Only delete temp files created for signing tx
humblenginr Sep 3, 2024
d97edee
refactor: create make_tx func
humblenginr Sep 4, 2024
b450579
fix: make sse implementation robust
humblenginr Sep 4, 2024
a1f88bf
fix: terminate peacefully when connection breaks
humblenginr Sep 4, 2024
b38dfaf
fix: error handling when incorrect seq number
humblenginr Sep 5, 2024
95c872f
fix: close opened file descriptor
humblenginr Sep 5, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For other performance charts see [gocoin.pl](https://gocoin.pl/gocoin_performanc

* 64-bit architecture OS and Go compiler.
* File system supporting files larger than 4GB.
* At least 32GB of system RAM (more recommended).
* At least 40GB of system RAM (more recommended).


**wallet**:
Expand Down
13 changes: 12 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
1.10.3
1.10.4:
* Testnet4 support. For now needs "CFG.Testnet4" set to true, otherwise still uses testnet3

1.10.3 - 2024-08-13:
* Tools/balio: Some improvements around blockchair.com and blockcypher.com API
* Tools/balio: Fixed balance fetching for Litecoin
* Lib: New function (btc.Tx).ContainsOrdFile(), as per github.com/casey/ord
Expand All @@ -23,6 +26,14 @@
* Lib: Fix in handing chain re-orgs when a new head has less blocks, but more POW (exposed by ongoing testnet3 stressing)
* Client/Network: improved the way how unfinished "getdata" is stored for later (when the send buffer is full)
* Client/Network: do not sent "ping" messages to peers that we have pending block downloads from
* Wallet: do not offer to save the password when "-p" switch was used
* Wallet: "-words" and "-xprv" now prevent tx signing and no longer need to be used together with "-l"
* Client: Fixed wallet.GetAllUnspent() for P2WSH address types (had to be broken unnoticed since Taproot was added)
* Lib: btc.EcdsaSign() can now create deterministc signatures, as per RFC6979
* Wallet: new command line/config switch "rfc6979" to create RFC6979 deterministic signatures
* Client/WebUI/MakeTx: Default Sequence value changed from 0 to -3 (same as other wallets on the market)
* Wallet: new command line switch "-locktime" to specify lock time value other than 0 (use with "-send")
* Wallet: Default Sequence value changed from 0 to -3 (0xfffffffd)

1.10.2 - 2022-09-06:
* Client: New config value "Memory.CompressBlockDB" (default true)
Expand Down
11 changes: 6 additions & 5 deletions client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ var (
LogBuffer = new(bytes.Buffer)
Log *log.Logger = log.New(LogBuffer, "", 0)

BlockChain *chain.Chain
GenesisBlock *btc.Uint256
Magic [4]byte
Testnet bool
BlockChain *chain.Chain
GenesisBlock *btc.Uint256
Magic [4]byte
Testnet bool
DefaultTcpPort uint16 = 8333

Last TheLastBlock

Expand Down Expand Up @@ -163,7 +164,7 @@ func BytesToString(val uint64) string {
return fmt.Sprintf("%.2f GB", float64(val)/1e9)
}

//max 6 characters
// max 6 characters
func UintToString(num uint64) string {
if num < 1e5 {
return fmt.Sprint(num) + " "
Expand Down
36 changes: 20 additions & 16 deletions client/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

const LastTrustedBTCBlock = "00000000000000000001fcf207ce30e9172433f815bf4ca0e90ecd0601286a20" // #817490
const LastTrustedTN3Block = "0000000000000f56395d3d0e54515ae310541b6c8e5a4311d05edbaed567211f" // #2536700
const LastTrustedTN4Block = "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043" // #0

var (
ConfigFile string = "gocoin.conf"
Expand All @@ -37,6 +38,7 @@ var (

CFG struct { // Options that can come from either command line or common file
Testnet bool
Testnet4 bool
ConnectOnly string
Datadir string
TextUI_Enabled bool
Expand Down Expand Up @@ -257,11 +259,17 @@ func InitConfig() {

// swap LastTrustedBlock if it's now from the other chain
if CFG.Testnet {
if new_config_file || CFG.LastTrustedBlock == LastTrustedBTCBlock {
CFG.LastTrustedBlock = LastTrustedTN3Block
if CFG.Testnet4 {
if new_config_file || CFG.LastTrustedBlock == LastTrustedBTCBlock || CFG.LastTrustedBlock == LastTrustedTN4Block {
CFG.LastTrustedBlock = LastTrustedTN4Block
}
} else {
if new_config_file || CFG.LastTrustedBlock == LastTrustedBTCBlock || CFG.LastTrustedBlock == LastTrustedTN3Block {
CFG.LastTrustedBlock = LastTrustedTN3Block
}
}
} else {
if new_config_file || CFG.LastTrustedBlock == LastTrustedTN3Block {
if new_config_file || CFG.LastTrustedBlock == LastTrustedTN3Block || CFG.LastTrustedBlock == LastTrustedTN4Block {
CFG.LastTrustedBlock = LastTrustedBTCBlock
}
}
Expand Down Expand Up @@ -310,7 +318,11 @@ func InitConfig() {

func DataSubdir() string {
if CFG.Testnet {
return "tstnet"
if CFG.Testnet4 {
return "ts4net"
} else {
return "tstnet"
}
} else {
return "btcnet"
}
Expand Down Expand Up @@ -413,28 +425,20 @@ func RPCPort() (res uint32) {

if CFG.RPC.TCPPort != 0 {
res = CFG.RPC.TCPPort
return
}
if CFG.Testnet {
res = 18332
} else {
res = 8332
res = uint32(DefaultTcpPort) - 1
}
return
}

func DefaultTcpPort() (res uint16) {
func ConfiguredTcpPort() (res uint16) {
mutex_cfg.Lock()
defer mutex_cfg.Unlock()

if CFG.Net.TCPPort != 0 {
res = CFG.Net.TCPPort
return
}
if CFG.Testnet {
res = 18333
} else {
res = 8333
res = DefaultTcpPort
}
return
}
Expand Down Expand Up @@ -471,7 +475,7 @@ func UnlockCfg() {

func CloseBlockChain() {
if BlockChain != nil {
fmt.Println("Closing BlockChain")
fmt.Println("Closing BlockChain at block", BlockChain.LastBlock().Height)
BlockChain.Close()
//BlockChain = nil
}
Expand Down
19 changes: 13 additions & 6 deletions client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ func host_init() {
common.GocoinHomeDir = common.CFG.Datadir + string(os.PathSeparator)

common.Testnet = common.CFG.Testnet // So chaging this value would will only affect the behaviour after restart
if common.CFG.Testnet { // testnet3
common.GenesisBlock = btc.NewUint256FromString("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")
common.Magic = [4]byte{0x0B, 0x11, 0x09, 0x07}
common.GocoinHomeDir += common.DataSubdir() + string(os.PathSeparator)
if common.CFG.Testnet {
if common.CFG.Testnet4 { // testnet4
common.GenesisBlock = btc.NewUint256FromString("00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043")
common.Magic = [4]byte{0x1c, 0x16, 0x3f, 0x28}
common.DefaultTcpPort = 48333
} else { // testnet3
common.GenesisBlock = btc.NewUint256FromString("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")
common.Magic = [4]byte{0x0B, 0x11, 0x09, 0x07}
common.DefaultTcpPort = 18333
}
} else {
common.GenesisBlock = btc.NewUint256FromString("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
common.Magic = [4]byte{0xF9, 0xBE, 0xB4, 0xD9}
common.GocoinHomeDir += common.DataSubdir() + string(os.PathSeparator)
common.DefaultTcpPort = 8333
}
common.GocoinHomeDir += common.DataSubdir() + string(os.PathSeparator)

// Lock the folder
os.MkdirAll(common.GocoinHomeDir, 0770)
Expand Down Expand Up @@ -78,7 +85,7 @@ func host_init() {
}

if common.Testnet {
ext.UTXOPrealloc = 19e6 // Around block #2600k
ext.UTXOPrealloc = 1e6 // New testnet4
} else {
ext.UTXOPrealloc = 120e6 // Around block #838k
}
Expand Down
8 changes: 7 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,15 @@ func HandleRpcBlock(msg *rpcapi.BlockSubmited) {
common.Last.Time = time.Now()
common.Last.Block = common.BlockChain.LastBlock()
common.UpdateScriptFlags(msg.VerifyFlags)
last_block := common.Last.Block
common.Last.Mutex.Unlock()

network.MutexRcv.Lock()
if last_block.Height > network.LastCommitedHeader.Height {
network.LastCommitedHeader = last_block
}
network.MutexRcv.Unlock()

msg.Done.Done()
}

Expand Down Expand Up @@ -455,7 +462,6 @@ func main() {

reset_save_timer() // we wil do one save try after loading, in case if ther was a rescan

peersdb.Testnet = common.Testnet
peersdb.ConnectOnly = common.CFG.ConnectOnly
peersdb.Services = common.Services
peersdb.InitPeers(common.GocoinHomeDir)
Expand Down
7 changes: 4 additions & 3 deletions client/miners.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
["BTC.COM", "BTC.COM/", ""],
["BTC.COM", "BTC.com/", ""],
["BTC.COM", "btc.com/", ""],
["BTC.COM", "", "3EhLZarJUNSfV6TWMZY1Nh5mi3FMsdHa5U"],
["BTC.COM", "btccom", ""],
["ViaBTC", "/ViaBTC/", ""],
["BTCC", "/BTCC/", ""],
["F2Pool", "/F2Pool/", "1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"],
Expand Down Expand Up @@ -58,8 +58,8 @@
["BTCPool", "btcpool", ""],
["BTCPool", "BTC-POOL", ""],
["SBICrypto", "/SBICrypto", ""],
["Mara Pool", "/Mara Pool/", ""],
["Mara Pool", "/MARA Pool", ""],
["Mara Pool", "Mara Pool", ""],
["Mara Pool", "MARA Pool", ""],
["one_more_mcd", "/one_more_mcd/", ""],
["Luxor", "Powered by Luxor", ""],
["bitdeer", "bitdeer/", ""],
Expand All @@ -73,6 +73,7 @@
["Lucky pool", "Lucky pool", ""],
["WhitePool", "WhitePool", ""],
["OCEAN", "OCEAN.XYZ", ""],
["ultimus", "/ultimus/", ""],
["RSK Merged", "_RSK_", ""],
["P2Pool", "_p2pool_", ""]
]
2 changes: 1 addition & 1 deletion client/network/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func BestExternalAddr() []byte {
if len(arr) > 0 {
binary.BigEndian.PutUint32(res[20:24], arr[0].IP)
}
binary.BigEndian.PutUint16(res[24:26], common.DefaultTcpPort())
binary.BigEndian.PutUint16(res[24:26], common.ConfiguredTcpPort())
return res
}

Expand Down
38 changes: 19 additions & 19 deletions client/network/peersdb/peerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var (
proxyPeer *PeerAddr // when this is not nil we should only connect to this single node
peerdb_mutex sync.Mutex

Testnet bool
ConnectOnly string
Services uint64 = 1

Expand All @@ -84,14 +83,6 @@ type PeerAddr struct {
lastSaved int64 // update the record only once per minute
}

func DefaultTcpPort() uint16 {
if Testnet {
return 18333
} else {
return 8333
}
}

func Lock() {
peerdb_mutex.Lock()
}
Expand Down Expand Up @@ -225,7 +216,7 @@ func (p *PeerAddr) UniqID() uint64 {
}

func NewAddrFromString(ipstr string, force_default_port bool) (p *PeerAddr, e error) {
port := DefaultTcpPort()
port := common.DefaultTcpPort
x := strings.Index(ipstr, ":")
if x != -1 {
if !force_default_port {
Expand All @@ -235,7 +226,7 @@ func NewAddrFromString(ipstr string, force_default_port bool) (p *PeerAddr, e er
return
}
if v > 0xffff {
e = errors.New("Port number too big")
e = errors.New("port number too big")
return
}
port = uint16(v)
Expand Down Expand Up @@ -541,7 +532,7 @@ func initSeeds(seeds []string, port uint16) {
//println(len(ad), "addrs from", seeds[i])
for j := range ad {
ip := net.ParseIP(ad[j])
if ip != nil && len(ip) == 16 {
if len(ip) == 16 {
p := NewPeer(nil)
p.Services = 0xFFFFFFFFFFFFFFFF
copy(p.Ip6[:], ip[:12])
Expand Down Expand Up @@ -569,13 +560,17 @@ func InitPeers(dir string) {
if ConnectOnly != "" {
x := strings.Index(ConnectOnly, ":")
if x == -1 {
ConnectOnly = fmt.Sprint(ConnectOnly, ":", DefaultTcpPort())
ConnectOnly = fmt.Sprint(ConnectOnly, ":", common.DefaultTcpPort)
}
oa, e := net.ResolveTCPAddr("tcp4", ConnectOnly)
if e != nil {
println(e.Error(), ConnectOnly)
os.Exit(1)
}
if len(oa.IP) < 16 {
println("ERROR: cCould not resolve IP addess of", ConnectOnly)
os.Exit(1)
}
proxyPeer = NewPeer(nil)
proxyPeer.Services = Services
copy(proxyPeer.Ip4[:], oa.IP[12:16])
Expand All @@ -584,26 +579,31 @@ func InitPeers(dir string) {
proxyPeer.Ip4[0], proxyPeer.Ip4[1], proxyPeer.Ip4[2], proxyPeer.Ip4[3], proxyPeer.Port)
} else if PeerDB.Count() < MinPeersInDB {
go func() {
if !Testnet {
switch common.DefaultTcpPort {
case 8333: // mainnet
initSeeds([]string{
"seed.bitcoin.sipa.be",
"dnsseed.bluematt.me",
"dnsseed.bitcoin.dashjr.org",
"dnsseed.bitcoin.dashjr-list-of-p2p-nodes.us",
"seed.bitcoinstats.com",
"seed.bitcoin.jonasschnelli.ch",
"seed.btc.petertodd.org",
"seed.btc.petertodd.net",
"seed.bitcoin.sprovoost.nl",
"seed.bitnodes.io",
"dnsseed.emzy.de",
"seed.bitcoin.wiz.biz",
}, 8333)
} else {
case 18333: // testnet3
initSeeds([]string{
"testnet-seed.bitcoin.jonasschnelli.ch",
"seed.tbtc.petertodd.org",
"seed.tbtc.petertodd.net",
"seed.testnet.bitcoin.sprovoost.nl",
"testnet-seed.bluematt.me",
}, 18333)
case 48333: // testnet4
initSeeds([]string{
"seed.testnet4.bitcoin.sprovoost.nl",
"seed.testnet4.wiz.biz",
}, 48333)
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion client/network/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func tcp_server() {
println("Check config value of Net.BindToIF - binding to any...")
ad.IP = net.IPv4(0, 0, 0, 0)
}
ad.Port = int(common.DefaultTcpPort())
ad.Port = int(common.ConfiguredTcpPort())

lis, e := net.ListenTCP("tcp4", &ad)
if e != nil {
Expand Down
Loading