From f488e7643b139a85e78f55972347b139d47bc0f9 Mon Sep 17 00:00:00 2001 From: btclinux Date: Thu, 28 Jul 2022 23:43:55 +0300 Subject: [PATCH] Add UFO --- bchain/coins/blockchain.go | 2 + bchain/coins/ufo/ufoparser.go | 63 ++++++++++++++++++++++++++++++ bchain/coins/ufo/uforpc.go | 58 ++++++++++++++++++++++++++++ configs/coins/ufo.json | 72 +++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 bchain/coins/ufo/ufoparser.go create mode 100644 bchain/coins/ufo/uforpc.go create mode 100644 configs/coins/ufo.json diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index 1fe7baae17..9efe9b0c3c 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -47,6 +47,7 @@ import ( "github.com/trezor/blockbook/bchain/coins/ritocoin" "github.com/trezor/blockbook/bchain/coins/snowgem" "github.com/trezor/blockbook/bchain/coins/trezarcoin" + "github.com/trezor/blockbook/bchain/coins/ufo" "github.com/trezor/blockbook/bchain/coins/unobtanium" "github.com/trezor/blockbook/bchain/coins/vertcoin" "github.com/trezor/blockbook/bchain/coins/viacoin" @@ -126,6 +127,7 @@ func init() { BlockChainFactories["BitZeny"] = bitzeny.NewBitZenyRPC BlockChainFactories["Trezarcoin"] = trezarcoin.NewTrezarcoinRPC BlockChainFactories["ECash"] = ecash.NewECashRPC + BlockChainFactories["UFO"] = ufo.NewUfoRPC } // GetCoinNameFromConfig gets coin name and coin shortcut from config file diff --git a/bchain/coins/ufo/ufoparser.go b/bchain/coins/ufo/ufoparser.go new file mode 100644 index 0000000000..e3c6149654 --- /dev/null +++ b/bchain/coins/ufo/ufoparser.go @@ -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 + } +} diff --git a/bchain/coins/ufo/uforpc.go b/bchain/coins/ufo/uforpc.go new file mode 100644 index 0000000000..df568de91a --- /dev/null +++ b/bchain/coins/ufo/uforpc.go @@ -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 +} diff --git a/configs/coins/ufo.json b/configs/coins/ufo.json new file mode 100644 index 0000000000..a5c72c3b96 --- /dev/null +++ b/configs/coins/ufo.json @@ -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": "" + } +}