package frontend import ( "net" "time" "git.hush.is/hush/lightwalletd/zrpc" "github.com/pkg/errors" ini "gopkg.in/ini.v1" ) // DefaultRPCTimeout bounds a single JSON-RPC round trip to dragonxd. // // Why 120s and not something tighter: the slowest legitimate call this daemon // makes is `coinsupply`, measured at 48s against a cold UTXO set (3s once the // node has cached the result). A timeout below that would turn a slow-but- // working call into a hard failure. 120s leaves ~2.5x headroom over the // slowest real call while still bounding a hang that is otherwise unbounded -- // calls were seen running past five minutes before the process was killed. const DefaultRPCTimeout = 120 * time.Second func NewZRPCFromConf(confPath string, timeout time.Duration) (*zrpc.Client, error) { cfg, err := ini.Load(confPath) if err != nil { return nil, errors.Wrap(err, "failed to read config file") } rpcaddr := cfg.Section("").Key("rpcbind").String() rpcport := cfg.Section("").Key("rpcport").String() username := cfg.Section("").Key("rpcuser").String() password := cfg.Section("").Key("rpcpassword").String() return NewZRPCFromCreds(net.JoinHostPort(rpcaddr, rpcport), username, password, timeout) } func NewZRPCFromCreds(addr, username, password string, timeout time.Duration) (*zrpc.Client, error) { // DragonX only supports HTTP POST mode and does not provide TLS by default. return zrpc.New(addr, username, password, timeout), nil }