Bitcoin Forum
May 14, 2024, 04:58:40 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin google protocol buffer error python django? serialized_payment_details  (Read 441 times)
derrend (OP)
Hero Member
*****
Offline Offline

Activity: 707
Merit: 505



View Profile WWW
June 04, 2014, 10:02:45 PM
 #1

Here is my problem guys,

I initialise the protofile as shown in the bitcoin for developers wiki shown here:

Code:
    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;
    }

throw this view into django which fetches the public key associated with a newly created address, hashes it into the correct format for a script, serializes the 'serialized_payment_details' field and returns a response object.

Code:
    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")

When I point my bitcoin v0.9 client at URI

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

I am met with an error

Code:
    [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

But it isn't missing the details field is it?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!