Skip to content

Commit

Permalink
Add UFO
Browse files Browse the repository at this point in the history
  • Loading branch information
btclinux committed Jul 28, 2022
1 parent 1801dc4 commit f488e76
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions bchain/coins/ufo/ufoparser.go
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
}
}
58 changes: 58 additions & 0 deletions bchain/coins/ufo/uforpc.go
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
}
72 changes: 72 additions & 0 deletions configs/coins/ufo.json
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": ""
}
}

0 comments on commit f488e76

Please sign in to comment.