Skip to content

Commit e24b5c9

Browse files
committed
much more txs
1 parent b7e2e95 commit e24b5c9

15 files changed

+446
-43
lines changed

addresses.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import hashlib
2+
import os
3+
import ecdsa
4+
import ecdsa.der
5+
import ecdsa.util
6+
from bitcoin import *
7+
import json
8+
import requests
9+
import node
10+
11+
b58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
12+
13+
14+
def base58encode(n):
15+
result = ''
16+
while n > 0:
17+
result = b58[n%58] + result
18+
n /= 58
19+
return result
20+
21+
def base256decode(s):
22+
result = 0
23+
for c in s:
24+
result = result * 256 + ord(c)
25+
return result
26+
27+
def countLeadingChars(s, ch):
28+
count = 0
29+
for c in s:
30+
if c == ch:
31+
count += 1
32+
else:
33+
break
34+
return count
35+
36+
# https://en.bitcoin.it/wiki/Base58Check_encoding
37+
def base58CheckEncode(version, payload):
38+
s = chr(version) + payload
39+
checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
40+
result = s + checksum
41+
leadingZeros = countLeadingChars(result, '\0')
42+
return '1' * leadingZeros + base58encode(base256decode(result))
43+
44+
def privateKeyToWif(key_hex):
45+
return base58CheckEncode(0x80, key_hex.decode('hex'))
46+
47+
def privateKeyToPublicKey(s):
48+
sk = ecdsa.SigningKey.from_string(s.decode('hex'), curve=ecdsa.SECP256k1)
49+
vk = sk.verifying_key
50+
return ('\04' + sk.verifying_key.to_string()).encode('hex')
51+
52+
def pubKeyToAddr(s):
53+
ripemd160 = hashlib.new('ripemd160')
54+
ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
55+
return base58CheckEncode(0, ripemd160.digest())
56+
57+
def keyToAddr(s):
58+
return pubKeyToAddr(privateKeyToPublicKey(s))
59+
60+
# Generate a random private key
61+
def generate_subkeys():
62+
a=[]
63+
a.append(os.urandom(subkey_complexity).encode('hex')) #subkey1
64+
a.append(os.urandom(subkey_complexity).encode('hex')) #subkey2
65+
return a
66+
67+
def generate_privatekey(phrase):
68+
keysum=phrase
69+
secret_exponent=hashlib.sha256(keysum).hexdigest()
70+
71+
privkey=privateKeyToWif(secret_exponent)
72+
return privkey
73+
74+
def generate_publicaddress(phrase):
75+
keysum=phrase
76+
secret_exponent=hashlib.sha256(keysum).hexdigest()
77+
address=keyToAddr(secret_exponent)
78+
return address
79+
80+
def getunspent(publicaddress): #REPLACE SOMEDAY WITH LOCAL
81+
url= "https://blockchain.info/unspent?active="+publicaddress
82+
a=requests.get(url)
83+
return json.loads(a.content)['unspent_outputs']

addresses.pyc

3.24 KB
Binary file not shown.

bitsource.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ def color_address(publicaddress):
9191
hashed=a.content #REPLACE THIS METHOD
9292

9393

94-
95-
9694
def read_tx(txhash):
9795
r=tx_lookup(txhash)
9896
m=''
@@ -154,6 +152,46 @@ def parse_colored_tx(metadata):
154152

155153
return results
156154

155+
def write_metadata(asset_quantities, otherdata):
156+
#PLAINTEXT SCRIPT TO BE ENCODED INTO OP RETURN using Transaction.make_info_script
157+
global encoded
158+
#work in hex
159+
result='4f410100' #OA + version 0100
160+
assetcount=str(len(asset_quantities))
161+
if len(assetcount)==1:
162+
assetcount='0'+assetcount
163+
result=result+assetcount
164+
165+
for asset in asset_quantities:
166+
167+
encoded=leb128.encode(asset)
168+
j=''
169+
print encoded
170+
for x in encoded:
171+
r=str(hex(int(x,2)))
172+
if len(r)==3:
173+
r='0'+r[2:3]
174+
else:
175+
r=r[2:len(r)]
176+
j=j+r
177+
178+
result=result+j
179+
180+
length=hex(len(otherdata))
181+
if len(length)==3:
182+
length=length[2:len(length)]
183+
length='0'+length
184+
else:
185+
length=length[2:len(length)]
186+
result=result+length
187+
result=result+otherdata.encode('hex')
188+
189+
return result
190+
#result=result+"\x"+assetcount
191+
192+
193+
194+
157195
def oa_tx(txid, inputcolors):
158196
txdata=tx_lookup(txid)
159197
message=read_tx(txid)
@@ -211,6 +249,7 @@ def oa_tx(txid, inputcolors):
211249

212250
def oa_in_block(n):
213251
messages=op_return_in_block(n)
252+
global markerposition
214253
results=[]
215254
for x in messages:
216255
metadata=x[1]
@@ -251,7 +290,11 @@ def oa_in_block(n):
251290
return results
252291

253292
def init():
254-
print oa_in_block(301271)
293+
#print oa_in_block(301271)
294+
q=write_metadata([57,12443],'')
295+
a=op_return_in_block(301271)[0][1]
296+
print "is "+str(q)
297+
print "should be "+str(a.encode('hex'))
255298

256299
init()
257300

bitsource.pyc

1.15 KB
Binary file not shown.

cointools.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
b58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
2020

2121

22-
subkey_complexity=32
23-
24-
standard_fee=0.0001
25-
minincrement=0.001 #min BTC per address (smallest addresses)
26-
increment_base=2
2722

2823
def base58encode(n):
2924
result = ''
@@ -91,21 +86,6 @@ def generate_publicaddress(subkey1,subkey2):
9186
address=keyToAddr(secret_exponent)
9287
return address
9388

94-
def check_address(public_address):
95-
p='https://blockchain.info/q/addressbalance/'
96-
p=p+public_address
97-
h=requests.get(p)
98-
if h.status_code==200:
99-
return h.content
100-
else:
101-
return -1
102-
103-
def check_address_subkeys(subkey1,subkey2):
104-
global h
105-
address=generate_publicaddress(subkey1,subkey2)
106-
107-
return check_address(address)
108-
10989
def generate_receiving_address(destination_address):
11090
global g,r
11191
a='https://blockchain.info/api/receive?method=create&address='
@@ -120,7 +100,6 @@ def generate_receiving_address(destination_address):
120100
return "ERROR"
121101

122102

123-
#'$receiving_address&callback=$callback_url
124103

125104
class subkeypair:
126105
subkey1='' #user
@@ -495,7 +474,7 @@ def make_info_script(info):
495474

496475
#MAX 75 bytes in info
497476
#TX not being accepted by blockchain.info
498-
def send_with_info(fromaddr,amt,destination, fee, secretexponent, info):
477+
def send_with_info(fromaddr,amt,destination, fee, secretexponent, info, privkey):
499478
global outs,inp, tx, tx2,totalin,b,amounts, ins,unspentbtc, detx
500479
amounts=[]
501480
outs=[]
@@ -530,6 +509,8 @@ def send_with_info(fromaddr,amt,destination, fee, secretexponent, info):
530509
tx=serialize(detx)
531510

532511
priv=hashlib.sha256(secretexponent).hexdigest()
512+
if len(privkey)>3:
513+
priv=privkey
533514
tx2=tx
534515
for i in range(0,outn-1):
535516
tx2=sign(tx2,i,priv)

cointools.pyc

-482 Bytes
Binary file not shown.

leb128.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ def ripemd160_encode(n):
55
m.update(n)
66
return m.hexdigest()
77

8+
def hash160(n):
9+
m=ripemd160_encode(n)
10+
return hashlib.sha256(m).hexdigest()
11+
12+
def ripehash(n):
13+
m=hashlib.sha256(n).hexdigest()
14+
return ripemd160_encode(m)
15+
816
def int_to_binary(n):
917
r=''
1018
while n>0:
@@ -19,6 +27,8 @@ def make_batches(n):
1927
b=int_to_binary(n)
2028
g=len(b)%7
2129
g=7-g
30+
if g==7:
31+
g=0
2232
for i in range(0,g):
2333
b='0'+str(b)
2434

leb128.pyc

360 Bytes
Binary file not shown.

node.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import requests
2+
import json
3+
4+
5+
node_url='127.0.0.1'#'71.198.63.116'#'199.188.192.144'#
6+
node_port='8332'
7+
username='barisser'
8+
password='2bf763d2132a2ccf3ea38077f79196ebd600f4a29aa3b1afd96feec2e7d80beb3d9e13d02d56de0f'
9+
10+
def connect(command,params):
11+
url='http://'+username+':'+password+'@'+node_url+':'+node_port
12+
headers={'content-type':'application/json'}
13+
payload=json.dumps({'method':command,'params':params})
14+
response=requests.get(url,headers=headers,data=payload)
15+
16+
response=json.loads(response.content)
17+
return response['result']

node.pyc

832 Bytes
Binary file not shown.

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TO DO
2+
3+
4+
5+
##ISSUES
6+
7+
1) Currently Create Raw Transactions can UNCOLOR coins by
8+
indisciminately using unspent inputs
9+
10+
2) How to make Color Address
11+
12+
13+
##IMPROVEMENTS
14+
make transactions a class
15+
16+
17+
####RESOLVED
18+
19+
3) Metadata bug, turned out LEB128 encoding was flawed in edge case

0 commit comments

Comments
 (0)