forked from trezor/blockbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ufo | ||
|
||
import ( | ||
"github.com/martinboehm/btcd/wire" | ||
"github.com/martinboehm/btcutil/chaincfg" | ||
"github.com/trezor/blockbook/bchain/coins/btc" | ||
) | ||
|
||
// magic numbers | ||
const ( | ||
MainnetMagic wire.BitcoinNet = 0xddb7d9fc | ||
TestnetMagic wire.BitcoinNet = 0xdbb8c0fb | ||
) | ||
|
||
// chain parameters | ||
var ( | ||
MainNetParams chaincfg.Params | ||
TestNetParams chaincfg.Params | ||
) | ||
|
||
func init() { | ||
MainNetParams = chaincfg.MainNetParams | ||
MainNetParams.Net = MainnetMagic | ||
MainNetParams.PubKeyHashAddrID = []byte{27} | ||
MainNetParams.ScriptHashAddrID = []byte{68} | ||
MainNetParams.Bech32HRPSegwit = "uf" | ||
|
||
TestNetParams = chaincfg.TestNet3Params | ||
TestNetParams.Net = TestnetMagic | ||
TestNetParams.PubKeyHashAddrID = []byte{111} | ||
TestNetParams.ScriptHashAddrID = []byte{130} | ||
TestNetParams.Bech32HRPSegwit = "ut" | ||
} | ||
|
||
// UfoParser handle | ||
type UfoParser struct { | ||
*btc.BitcoinLikeParser | ||
} | ||
|
||
// NewUfoParser returns new UfoParser instance | ||
func NewUfoParser(params *chaincfg.Params, c *btc.Configuration) *UfoParser { | ||
return &UfoParser{BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c)} | ||
} | ||
|
||
// GetChainParams contains network parameters for the main UFO network, | ||
// and the test UFO network | ||
func GetChainParams(chain string) *chaincfg.Params { | ||
if !chaincfg.IsRegistered(&MainNetParams) { | ||
err := chaincfg.Register(&MainNetParams) | ||
if err == nil { | ||
err = chaincfg.Register(&TestNetParams) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
switch chain { | ||
case "test": | ||
return &TestNetParams | ||
default: | ||
return &MainNetParams | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ufo | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/golang/glog" | ||
"github.com/trezor/blockbook/bchain" | ||
"github.com/trezor/blockbook/bchain/coins/btc" | ||
) | ||
|
||
// UfoRPC is an interface to JSON-RPC bitcoind service. | ||
type UfoRPC struct { | ||
*btc.BitcoinRPC | ||
} | ||
|
||
// NewUfoRPC returns new UfoRPC instance. | ||
func NewUfoRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) { | ||
b, err := btc.NewBitcoinRPC(config, pushHandler) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
s := &UfoRPC{ | ||
b.(*btc.BitcoinRPC), | ||
} | ||
s.RPCMarshaler = btc.JSONMarshalerV2{} | ||
s.ChainConfig.SupportsEstimateFee = false | ||
|
||
return s, nil | ||
} | ||
|
||
// Initialize initializes UfoRPC instance. | ||
func (b *UfoRPC) Initialize() error { | ||
ci, err := b.GetChainInfo() | ||
if err != nil { | ||
return err | ||
} | ||
chainName := ci.Chain | ||
|
||
glog.Info("Chain name ", chainName) | ||
params := GetChainParams(chainName) | ||
|
||
// always create parser | ||
b.Parser = NewUfoParser(params, b.ChainConfig) | ||
|
||
// parameters for getInfo request | ||
if params.Net == MainnetMagic { | ||
b.Testnet = false | ||
b.Network = "livenet" | ||
} else { | ||
b.Testnet = true | ||
b.Network = "testnet" | ||
} | ||
|
||
glog.Info("rpc: block chain ", params.Name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"coin": { | ||
"name": "UFO", | ||
"shortcut": "UFO", | ||
"label": "UFO", | ||
"alias": "ufo" | ||
}, | ||
"ports": { | ||
"backend_rpc": 8087, | ||
"backend_message_queue": 38387, | ||
"blockbook_internal": 9087, | ||
"blockbook_public": 9187 | ||
}, | ||
"ipc": { | ||
"rpc_url_template": "http://127.0.0.1:{{.Ports.BackendRPC}}", | ||
"rpc_user": "rpc", | ||
"rpc_pass": "rpc", | ||
"rpc_timeout": 25, | ||
"message_queue_binding_template": "tcp://127.0.0.1:{{.Ports.BackendMessageQueue}}" | ||
}, | ||
"backend": { | ||
"package_name": "backend-ufo", | ||
"package_revision": "1", | ||
"system_user": "ufo", | ||
"version": "0.18.1", | ||
"binary_url": "https://github.com/fiscalobject/ufo/releases/download/v0.18.1/ufo-0.18.1-linux64.tar.gz", | ||
"verification_type": "", | ||
"verification_source": "", | ||
"extract_command": "tar -C backend -xf", | ||
"exclude_files": [ | ||
"ufo-qt" | ||
], | ||
"exec_command_template": "{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/ufod -datadir={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend -conf={{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf -pid=/run/{{.Coin.Alias}}/{{.Coin.Alias}}.pid", | ||
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/*.log", | ||
"postinst_script_template": "", | ||
"service_type": "forking", | ||
"service_additional_params_template": "", | ||
"protect_memory": true, | ||
"mainnet": true, | ||
"server_config_file": "bitcoin_like.conf", | ||
"client_config_file": "bitcoin_like_client.conf", | ||
"additional_params": { | ||
"whitelist": "127.0.0.1" | ||
} | ||
}, | ||
"blockbook": { | ||
"package_name": "blockbook-ufo", | ||
"system_user": "blockbook-ufo", | ||
"internal_binding_template": ":{{.Ports.BlockbookInternal}}", | ||
"public_binding_template": ":{{.Ports.BlockbookPublic}}", | ||
"explorer_url": "", | ||
"additional_params": "", | ||
"block_chain": { | ||
"parse": true, | ||
"mempool_workers": 8, | ||
"mempool_sub_workers": 2, | ||
"block_addresses_to_keep": 300, | ||
"xpub_magic": 76067358, | ||
"xpub_magic_segwit_p2sh": 77429938, | ||
"xpub_magic_segwit_native": 78792518, | ||
"slip44": 202, | ||
"additional_params": { | ||
"fiat_rates": "coingecko", | ||
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ufocoin\", \"periodSeconds\": 60}" | ||
} | ||
} | ||
}, | ||
"meta": { | ||
"package_maintainer": "", | ||
"package_maintainer_email": "" | ||
} | ||
} |