我试图在我们的Openchain服务器中提交变异但没有成功。我想我的地址和密钥不正确。下面是我认为可能存在问题的代码。
def get_mutation(namespace, path, value):
r = openchain_pb2.Record()
m = openchain_pb2.Mutation()
m.namespace = namespace
rv = openchain_pb2.RecordValue()
rx=m.records.add()
rv.data = value
rx.value.CopyFrom(rv)
#r.key = '/p2pkh/XneAi6WTqcubvJaFGN5BRRMPmhBf3xEKew/'
rx.key = path
rx.version = sha256('1')
return m
def submit(session, mutation, pub_key, private_key):
netopen_submit=urlparse.urljoin(netopenchain_url, "submit")
mutations = mutation.SerializeToString()
print "Mutations\t",mutations
# Hash the mutation byte string using double SHA-256
final_hash = double_sha256(mutations)
# Sign it with the private key using Secp256k1
sig = ecdsa_sign(final_hash, private_key)
print ecdsa_verify(final_hash, sig, pub_key)
post_data = dict(
mutation=binascii.hexlify(mutations),
signatures=dict(
# The matching public key must be submitted along with the
# signature
pub_key=binascii.hexlify(pub_key),
signature=binascii.hexlify(sig),
)
)
header = {'content-type' : 'application/json;charset=utf8',"User- Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5)AppleWebKit 537.36 (KHTML, like Gecko) Chrome"}
r = session.post(netopen_submit, headers=header, json= post_data)#
if r.status_code != 200:
return -1
print json.dumps(post_data)
prepared = r.request
return r.json()
def getKeysAndAddress(password):
priv = sha256(password);
pub = privkey_to_pubkey(priv)
addr = pubkey_to_address(pub)
return priv, pub, addr
privatekey,publickey,myaddress = getKeysAndAddress("poverty myself when avocado pink slot unfold appear recall liar teach stand")
mut_buf = get_mutation(netopen_namespace,mypath,'stampnumber9')
submit(session, mut_buf, publickey, privatekey)
myaddress等于< 1ukGbi7TXMRBiEWefRBfnc9vuPKBmDd6K'在运行getKeysAndAddress
之后然而,Openchain网站上显示的地址可能是XneAi6WTqcubvJaFGN5BRRMPmhBf3xEKew。 每当我尝试插入由生成的密钥签名的突变时,我都会收到错误。
不知怎的,我认为getKeysAndAddress函数不正确。