示例#1
0
func (bc *BtcCred) SignOcReq(req *msg.OcReq, conf *util.BitcoindConf) error {
	h, err := getReqSigDataHash(req)
	if err != nil {
		return err
	}
	hb64 := base64.StdEncoding.EncodeToString(h)

	msg, err := btcjson.NewSignMessageCmd(nil, bc.Addr, hb64)
	if err != nil {
		return fmt.Errorf("error while making cmd: %v", err.Error())
	}
	json, err := msg.MarshalJSON()
	if err != nil {
		return fmt.Errorf("error while marshaling: %v", err.Error())
	}
	resp, err := btcjson.RpcCommand(conf.User, conf.Password, conf.Server, json)
	if err != nil {
		return fmt.Errorf("error while making bitcoind JSON-RPC: %v", err.Error())
	}
	sig, ok := resp.Result.(string)
	if !ok {
		return errors.New("error during bitcoind JSON-RPC")
	}

	req.Coins = append(req.Coins, fmt.Sprintf(bc.Addr))
	req.CoinSigs = append(req.CoinSigs, fmt.Sprintf(sig))

	return nil
}
示例#2
0
func verifyBtcSig(reqHash []byte, addr string, sig string, conf *util.BitcoindConf) (bool, error) {
	hb64 := base64.StdEncoding.EncodeToString(reqHash)

	msg, err := btcjson.NewVerifyMessageCmd(nil, addr, sig, hb64)
	if err != nil {
		return false, fmt.Errorf("error while making cmd: %v", err.Error())
	}
	json, err := msg.MarshalJSON()
	if err != nil {
		return false, fmt.Errorf("error while marshaling: %v", err.Error())
	}
	resp, err := btcjson.RpcCommand(conf.User, conf.Password, conf.Server, json)
	if err != nil {
		return false, fmt.Errorf(
			"error while making bitcoind JSON-RPC: %v", err.Error())
	}
	if resp.Error != nil {
		return false, resp.Error
	}
	verifyResult, ok := resp.Result.(bool)
	if !ok {
		return false, fmt.Errorf("error during bitcoind JSON-RPC: %v", err.Error())
	}

	return verifyResult, nil
}
示例#3
0
func getAnyBtcAddr(conf *util.BitcoindConf) (string, error) {
	msg, err := btcjson.NewListReceivedByAddressCmd(nil, 0, true)
	if err != nil {
		return "", err
	}

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

	resp, err := btcjson.RpcCommand(conf.User, conf.Password, conf.Server, json)
	if err != nil {
		return "", err
	}

	for _, r := range resp.Result.([]interface{}) {
		result := r.(map[string]interface{})
		return result["address"].(string), nil
	}

	return "", errors.New("no address found")
}