使用python django比特币谷歌协议缓冲区错误?缺少serialized_pa​​yment_details

时间:2014-06-03 06:40:44

标签: python django serialization protocol-buffers bitcoin

这是我的问题,

我初始化了protofile,如比特币所示,这里显示的开发人员维基:

package payments;
option java_package = "org.bitcoin.protocols.payments";
option java_outer_classname = "Protos";

message Output {
        optional uint64 amount = 1 [default = 0];
        required bytes script = 2;
}
message PaymentDetails {
        optional string network = 1 [default = "test"];
        repeated Output outputs = 2;
        required uint64 time = 3;
        optional uint64 expires = 4;
        optional string memo = 5;
        optional string payment_url = 6;
        optional bytes merchant_data = 7;
}
message PaymentRequest {
        optional uint32 payment_details_version = 1 [default = 1];
        optional string pki_type = 2 [default = "none"];
        optional bytes pki_data = 3;
        required bytes serialized_payment_details = 4;
        optional bytes signature = 5;
}
message X509Certificates {
        repeated bytes certificate = 1;
}
message Payment {
        optional bytes merchant_data = 1;
        repeated bytes transactions = 2;
        repeated Output refund_to = 3;
        optional string memo = 4;
}
message PaymentACK {
        required Payment payment = 1;
        optional string memo = 2;
}

将此视图放入django中,该django获取与新创建的地址关联的公钥,将其哈希为正确的脚本格式,序列化' serialized_pa​​yment_details'字段并返回响应对象。

def paymentobject(request):

    def addr_160(pub):
        h3 = hashlib.sha256(unhexlify(pub))
        return hashlib.new('ripemd160', h3.digest())

    x = payments_pb2

    btc_address = bc.getnewaddress()

    pubkey_hash = bc.validateaddress(btc_address).pubkey
    pubkey_hash160 = addr_160(pubkey_hash).hexdigest()
    hex_script = "76" + "a9" + "14" + pubkey_hash160 + "88" + "ac"
    serialized_script = hex_script.decode("hex")

    xpd = x.PaymentDetails()
    xpd.time = int(time())
    xpd.outputs.add(amount = 0, script = serialized_script)

    xpr = x.PaymentRequest()
    xpr.serialized_payment_details = xpd.SerializeToString()

    return HttpResponse(xpr.SerializeToString(), content_type="application/octet-stream")

当我将比特币v0.9客户端指向URI

bitcoin:?r=http://127.0.0.1:8000/paymentobject

我遇到了错误

[libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse message of type "payments.PaymentRequest" because it is missing required fields: serialized_payment_details

但它不是缺少细节字段吗?

非常感谢任何帮助,谢谢:)

1 个答案:

答案 0 :(得分:0)

答案是(在撰写本文时)您不能将{0}指定为Output.amount。比特币-qt 0.9客户认为它是灰尘,不允许交易继续进行。

更多信息here