MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / payment_request

Function payment_request

examples/bip-0070-payment-protocol.py:34–65  ·  view source on GitHub ↗

Generates a http PaymentRequest object

()

Source from the content-addressed store, hash-verified

32from time import time
33
34def payment_request():
35 """Generates a http PaymentRequest object"""
36
37 bc = Proxy()
38 btc = bc.getnewaddress()
39
40# Setting the 'amount' field to 0 (zero) should prompt the user to enter
41# the amount for us but a bug in bitcoin core qt version 0.9.1 (at time of
42# writing) wrongly informs us that the value is too small and aborts.
43# https://github.com/bitcoin/bitcoin/issues/3095
44# Also there can be no leading 0's (zeros).
45 btc_amount = 100000
46 serialized_pubkey = btc.to_scriptPubKey()
47
48 pdo = o.PaymentDetails()
49 #pdo.network = 'test'
50 pdo.outputs.add(amount = btc_amount,script = serialized_pubkey)
51 pdo.time = int(time())
52 pdo.memo = 'String shown to user before confirming payment'
53 pdo.payment_url = 'http://payment_ack.url'
54
55 pro = o.PaymentRequest()
56 pro.serialized_payment_details = pdo.SerializeToString()
57
58 sds_pr = pro.SerializeToString()
59
60 open('sds_pr_blob', 'wb').write(sds_pr)
61 headers = {'Content-Type': 'application/bitcoin-payment',
62 'Accept': 'application/bitcoin-paymentrequest'}
63 http_response_object = urllib2.Request('file:sds_pr_blob', None, headers)
64
65 return http_response_object
66
67
68def payment_ack(serialized_Payment_message):

Callers

nothing calls this directly

Calls 3

getnewaddressMethod · 0.95
ProxyClass · 0.90
to_scriptPubKeyMethod · 0.45

Tested by

no test coverage detected