mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 22:26:47 +00:00

* [NOD-303] Implement get transaction by id for api server * [NOD-303] Make routeParamTxID a constant * [NOD-303] Change database is not current error. * [NOD-303] Add ID to TransactionInput and TransactionOutput models * [NOD-303] Change transactions_outputs table name to transaction_outputs and transactions_inputs to transaction_inputs * [NOD-303] Add json annotations to transaction response types * [NOD-303] Split server package * [NOD-303] Add GetTransactionByHashHandler * [NOD-303] Add comments to exported functions and variables * [NOD-303] Put response types in a separate file * [NOD-303] Rename functions
41 lines
845 B
Go
41 lines
845 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/daglabs/btcd/apiserver/config"
|
|
"github.com/daglabs/btcd/rpcclient"
|
|
"io/ioutil"
|
|
)
|
|
|
|
func connectToServer(cfg *config.Config) (*apiServerClient, error) {
|
|
var cert []byte
|
|
if !cfg.DisableTLS {
|
|
var err error
|
|
cert, err = ioutil.ReadFile(cfg.RPCCert)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error reading certificates file: %s", err)
|
|
}
|
|
}
|
|
|
|
connCfg := &rpcclient.ConnConfig{
|
|
Host: cfg.RPCServer,
|
|
Endpoint: "ws",
|
|
User: cfg.RPCUser,
|
|
Pass: cfg.RPCPassword,
|
|
DisableTLS: cfg.DisableTLS,
|
|
}
|
|
|
|
if !cfg.DisableTLS {
|
|
connCfg.Certificates = cert
|
|
}
|
|
|
|
client, err := newAPIServerClient(connCfg)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error connecting to address %s: %s", cfg.RPCServer, err)
|
|
}
|
|
|
|
log.Infof("Connected to server %s", cfg.RPCServer)
|
|
|
|
return client, nil
|
|
}
|