我有一个正在网上玩的脚本
它有效,但是我正在尝试找出另外一个步骤
import ecdsa
import ecdsa.der
import ecdsa.util
import hashlib
import os
import re
import struct
b58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def base58encode(n):
result = ''
while n > 0:
result = b58[n%58] + result
n /= 58
return result
def base256decode(s):
result = 0
for c in s:
result = result * 256 + ord(c)
return result
def countLeadingChars(s, ch):
count = 0
for c in s:
if c == ch:
count += 1
else:
break
return count
# https://en.bitcoin.it/wiki/Base58Check_encoding
def base58CheckEncode(version, payload):
s = chr(version) + payload
checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
result = s + checksum
leadingZeros = countLeadingChars(result, '\0')
return '1' * leadingZeros + base58encode(base256decode(result))
def privateKeyToWif(key_hex):
return base58CheckEncode(0x80, key_hex.decode('hex'))
def privateKeyToPublicKey(s):
sk = ecdsa.SigningKey.from_string(s.decode('hex'), curve=ecdsa.SECP256k1)
vk = sk.verifying_key
return ('\04' + sk.verifying_key.to_string()).encode('hex')
def pubKeyToAddr(s):
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
return base58CheckEncode(0, ripemd160.digest())
def keyToAddr(s):
return pubKeyToAddr(privateKeyToPublicKey(s))
# Generate a random private key
private_key = os.urandom(32).encode('hex')
print "%s"% privateKeyToWif(private_key)
print "%s"% keyToAddr(private_key)
import urllib
link = "http://127.0.0.1:3001/insight-api/addr/(ADDR)/balance"
f = urllib.urlopen(link)
myfile = f.read()
print myfile
最后一部分是我的工作。我还发现,在网络上,我尝试了一些选项,但没有尝试,接下来要做的就是将结果打印到txt文件中。
最佳答案
您能更具体地回答这个问题吗?
我对您的问题的解释是,您正在尝试替换(ADDR)
link = "http://127.0.0.1:3001/insight-api/addr/(ADDR)/balance"
使用keyToAddr(private_key)返回的值,在这种情况下,您应该能够使用
link = "http://127.0.0.1:3001/insight-api/addr/"+keyToAddr(private_key)+"/balance"
关于python - 将生成的短语添加到网址中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40567579/