commit 69ee0bd0de551991a8048f1f7cccc4432b1284b5
parent 89a52a8273b4febf5e9e7aba4994a2aff91f1ab1
Author: ThomasV <thomasv@gitorious>
Date: Mon, 16 Feb 2015 14:05:04 +0100
new scripts: bip70 and estimate_fee
Diffstat:
2 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/scripts/bip70 b/scripts/bip70
@@ -0,0 +1,59 @@
+# create a BIP70 payment request signed with a certificate
+
+import tlslite
+import time
+import hashlib
+
+from electrum import paymentrequest_pb2 as pb2
+from electrum.transaction import Transaction
+from electrum import bitcoin
+from electrum import x509
+
+
+chain_file = 'mychain.pem'
+cert_file = 'mycert.pem'
+amount = 1000000
+address = "18U5kpCAU4s8weFF8Ps5n8HAfpdUjDVF64"
+memo = "blah"
+out_file = "payreq"
+
+
+with open(chain_file, 'r') as f:
+ chain = tlslite.X509CertChain()
+ chain.parsePemList(f.read())
+
+certificates = pb2.X509Certificates()
+certificates.certificate.extend(map(lambda x: str(x.bytes), chain.x509List))
+
+with open(cert_file, 'r') as f:
+ rsakey = tlslite.utils.python_rsakey.Python_RSAKey.parsePEM(f.read())
+
+
+def make_payment_request(amount, script, memo):
+ """Generates a http PaymentRequest object"""
+ pd = pb2.PaymentDetails()
+ pd.outputs.add(amount=amount, script=script)
+ now = int(time.time())
+ pd.time = now
+ pd.expires = now + 15*60
+ pd.memo = memo
+ pd.payment_url = 'http://payment_ack.url'
+ pr = pb2.PaymentRequest()
+ pr.serialized_payment_details = pd.SerializeToString()
+ pr.pki_type = 'x509+sha256'
+ pr.pki_data = certificates.SerializeToString()
+ pr.signature = ''
+ msgBytes = bytearray(pr.SerializeToString())
+ hashBytes = bytearray(hashlib.sha256(msgBytes).digest())
+ sig = rsakey.sign(x509.PREFIX_RSA_SHA256 + hashBytes)
+ pr.signature = bytes(sig)
+ return pr.SerializeToString()
+
+
+script = Transaction.pay_script('address', address).decode('hex')
+
+pr_string = make_payment_request(amount, script, memo)
+with open(out_file,'wb') as f:
+ f.write(pr_string)
+
+print "Payment request was written to file '%s'"%out_file
diff --git a/scripts/estimate_fee b/scripts/estimate_fee
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+import util, json
+peers = util.get_peers()
+results = util.send_request(peers, {'method':'blockchain.estimatefee','params':[1]})
+print json.dumps(results, indent=4)
+
+
+
+