Exemple #1
0
// send sends a JSON-RPC command to the specified RPC server and examines the
// results for various error conditions.  It either returns a valid result or
// an appropriate error.
func send(cfg *config, msg []byte) (interface{}, error) {
	var reply btcjson.Reply
	var err error
	if cfg.NoTLS || (cfg.RPCCert == "" && !cfg.TLSSkipVerify) {
		reply, err = btcjson.RpcCommand(cfg.RPCUser, cfg.RPCPassword,
			cfg.RPCServer, msg)
	} else {
		var pem []byte
		if cfg.RPCCert != "" {
			pem, err = ioutil.ReadFile(cfg.RPCCert)
			if err != nil {
				return nil, err
			}
		}
		reply, err = btcjson.TlsRpcCommand(cfg.RPCUser,
			cfg.RPCPassword, cfg.RPCServer, msg, pem,
			cfg.TLSSkipVerify)
	}
	if err != nil {
		return nil, err
	}

	if reply.Error != nil {
		return nil, reply.Error
	}

	return reply.Result, nil
}
Exemple #2
0
func getBestBlockHash() (string, error) {
	cmd, err := btcjson.NewGetBestBlockHashCmd("blocksafari")
	if err != nil {
		return "", err
	}

	msg, err := json.Marshal(cmd)
	if err != nil {
		return "", err
	}

	reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false)
	if err != nil {
		return "", err
	}
	if reply.Error != nil {
		return "", reply.Error
	}

	return reply.Result.(string), nil
}
Exemple #3
0
func getBlockCount() (float64, error) {
	cmd, err := btcjson.NewGetBlockCountCmd("blocksafari")
	if err != nil {
		return -1, err
	}

	msg, err := json.Marshal(cmd)
	if err != nil {
		return -1, err
	}

	reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false)
	if err != nil {
		return -1, err
	}

	if reply.Error != nil {
		return -1, reply.Error
	}

	return reply.Result.(float64), nil
}
Exemple #4
0
func getRawTx(tx string) (interface{}, error) {
	cmd, err := btcjson.NewGetRawTransactionCmd("blocksafari", tx, 1)
	if err != nil {
		return nil, err
	}

	msg, err := json.Marshal(cmd)
	if err != nil {
		return nil, err
	}

	reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false)
	if err != nil {
		return nil, err
	}

	if reply.Error != nil {
		return nil, reply.Error
	}

	return reply.Result, nil
}
Exemple #5
0
func getBlock(block string, withTx bool) (btcjson.BlockResult, error) {
	var result btcjson.BlockResult

	cmd, err := btcjson.NewGetBlockCmd("blocksafari", block, true, withTx)
	if err != nil {
		return result, err
	}

	msg, err := json.Marshal(cmd)
	if err != nil {
		return result, err
	}

	reply, err := btcjson.TlsRpcCommand(cfg.RPCUser, cfg.RPCPassword, cfg.RPCServer, msg, pem, false)
	if err != nil {
		return result, err
	}

	if reply.Error != nil {
		return result, reply.Error
	}

	return reply.Result.(btcjson.BlockResult), nil
}