本文整理汇总了Python中tools.det_hash函数的典型用法代码示例。如果您正苦于以下问题:Python det_hash函数的具体用法?Python det_hash怎么用?Python det_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了det_hash函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: block_check
def block_check(block, DB):
if 'error' in block or 'error' in DB: return False
if type(block)!=type({'a':1}):
print('type error')
return False
#print('DB: ' +str(DB))
length=copy.deepcopy(DB['length'])
if int(block['length'])!=int(length)+1: return False
if block['diffLength']!=hexSum(DB['diffLength'],
hexInvert(block['target'])):
print('diff length')
return False
if length >= 0:
if tools.det_hash(db_get(length, DB))!=block['prevHash']:
return False
a=copy.deepcopy(block)
a.pop('nonce')
if u'target' not in block.keys(): return False
half_way={u'nonce':block['nonce'], u'halfHash':tools.det_hash(a)}
if tools.det_hash(half_way)>block['target']: return False
if block['target']!=target(DB, block['length']): return False
earliest=median(recent_blockthings('time', DB))
if 'time' not in block: return False
if block['time']>time.time(): return False
if block['time']<earliest: return False
return True
开发者ID:gojira,项目名称:basiccoin,代码行数:26,代码来源:blockchain.py
示例2: slasher_verify
def slasher_verify(tx, txs, out, DB):
address=tools.addr(tx)
acc=tools.db_get(address)
if acc['secrets'][str(tx['on_block'])]['slashed']:
tools.log('Someone already slashed them, or they already took the reward.')
return False
if not sign_verify(tx['tx1'], [], [''], {}):
tools.log('one was not a valid tx')
return False
if not sign_verify(tx['tx2'], [], [''], {}):
tools.log('two was not a valid tx')
return False
tx1=copy.deepcopy(tx['tx1'])
tx2=copy.deepcopy(tx['tx2'])
tx1.pop('signatures')
tx2.pop('signatures')
tx1=unpackage(package(tx1))
tx2=unpackage(package(tx2))
msg1=tools.det_hash(tx1)
msg2=tools.det_hash(tx2)
if msg1==msg2:
tools.log('this is the same tx twice...')
return False
if tx1['on_block']!=tx2['on_block']:
tools.log('these are on different lengths')
return False
return True
开发者ID:appcoreopc,项目名称:slasher,代码行数:27,代码来源:transactions.py
示例3: slasher_verify
def slasher_verify(tx, txs, out, DB):
address = tools.addr(tx)
acc = tools.db_get(address)
if acc["secrets"][str(tx["on_block"])]["slashed"]:
tools.log("Someone already slashed them, or they already took the reward.")
return False
if not sign_verify(tx["tx1"], [], [""], {}):
tools.log("one was not a valid tx")
return False
if not sign_verify(tx["tx2"], [], [""], {}):
tools.log("two was not a valid tx")
return False
tx1 = copy.deepcopy(tx["tx1"])
tx2 = copy.deepcopy(tx["tx2"])
tx1.pop("signatures")
tx2.pop("signatures")
tx1 = unpackage(package(tx1))
tx2 = unpackage(package(tx2))
msg1 = tools.det_hash(tx1)
msg2 = tools.det_hash(tx2)
if msg1 == msg2:
tools.log("this is the same tx twice...")
return False
if tx1["on_block"] != tx2["on_block"]:
tools.log("these are on different lengths")
return False
return True
开发者ID:jtremback,项目名称:FlyingFox,代码行数:27,代码来源:transactions.py
示例4: block_check
def block_check(block, DB):
def log_(txt): pass #return tools.log(txt)
def tx_check(txs):
start = copy.deepcopy(txs)
out = []
start_copy = []
while start != start_copy:
if start == []:
return False # Block passes this test
start_copy = copy.deepcopy(start)
if transactions.tx_check[start[-1]['type']](start[-1], out, [''], DB):
out.append(start.pop())
else:
return True # Block is invalid
return True # Block is invalid
if not isinstance(block, dict): return False
if 'error' in block: return False
if not tools.E_check(block, 'length', [int]):
log_('no length')
return False
length = DB['length']
if int(block['length']) != int(length) + 1:
log_('wrong longth')
return False
if block['diffLength'] != hexSum(DB['diffLength'],
hexInvert(block['target'])):
log_('diflength error')
return False
if length >= 0:
if tools.det_hash(tools.db_get(length, DB)) != block['prevHash']:
log_('det hash error')
return False
a = copy.deepcopy(block)
a.pop('nonce')
if u'target' not in block.keys():
log_('target error')
return False
half_way = {u'nonce': block['nonce'], u'halfHash': tools.det_hash(a)}
if tools.det_hash(half_way) > block['target']:
log_('det hash error 2')
return False
if block['target'] != target.target(DB, block['length']):
log_('wrong target')
return False
earliest = median(recent_blockthings('times', DB, custom.mmm))
if 'time' not in block:
log_('no time')
return False
if block['time'] > time.time()+60*6:
log_('too late')
return False
if block['time'] < earliest:
log_('too early')
return False
if tx_check(block['txs']):
log_('tx check')
return False
return True
开发者ID:truthcoin,项目名称:skunkworks,代码行数:58,代码来源:blockchain.py
示例5: POW
def POW(block, restart_signal):
halfHash = tools.det_hash(block)
block[u'nonce'] = random.randint(0, 10000000000000000000000000000000000000000)
count = 0
while tools.det_hash({u'nonce': block['nonce'],
u'halfHash': halfHash}) > block['target']:
count += 1
block[u'nonce'] += 1
if restart_signal.is_set():
restart_signal.clear()
return {'solution_found': True}
return block
开发者ID:AltCoinsLand,项目名称:basiccoin,代码行数:12,代码来源:miner.py
示例6: POW
def POW(block, hashes, target):
halfHash=tools.det_hash(block)
block[u'nonce']=random.randint(0,100000000000000000)
count=0
while tools.det_hash({u'nonce':block['nonce'], u'halfHash':halfHash})>target:
count+=1
block[u'nonce']+=1
if count>hashes:
return {'error':False}
''' for testing sudden loss in hashpower from miners.
if block[u'length']>150:# and block[u'nonce']%10==0: time.sleep(0.1)
else: time.sleep(0.01)
'''
return block
开发者ID:Fangang,项目名称:basiccoin,代码行数:14,代码来源:consensus.py
示例7: block_check
def block_check(block, DB):
def tx_check(txs):
start = copy.deepcopy(txs)
out = []
start_copy = []
while start != start_copy:
if start == []:
return False # Block passes this test
start_copy = copy.deepcopy(start)
if transactions.tx_check[start[-1]['type']](start[-1], out, DB):
out.append(start.pop())
else:
return True # Block is invalid
return True # Block is invalid
if not isinstance(block, dict):
return False
if 'error' in block:
return False
if 'length' not in block:
return False
length = DB['length']
if int(block['length']) != int(length) + 1:
return False
if block['diffLength'] != hexSum(DB['diffLength'],
hexInvert(block['target'])):
return False
if length >= 0:
if tools.det_hash(db_get(length, DB)) != block['prevHash']:
return False
a = copy.deepcopy(block)
a.pop('nonce')
if u'target' not in block.keys():
return False
half_way = {u'nonce': block['nonce'], u'halfHash': tools.det_hash(a)}
if tools.det_hash(half_way) > block['target']:
return False
if block['target'] != target(DB, block['length']):
return False
earliest = median(recent_blockthings('time', DB, custom.mmm))
if 'time' not in block:
return False
if block['time'] > time.time():
return False
if block['time'] < earliest:
return False
if tx_check(block['txs']):
return False
if len(filter(lambda tx: tx['type']=='mint', block['txs']))!=1:
return False
return True
开发者ID:incorpusyehtee,项目名称:centralized-coin,代码行数:50,代码来源:blockchain.py
示例8: reward_verify
def reward_verify(tx, txs, out, DB):
address = tools.addr(tx)
acc = tools.db_get(address)
relative_reward = tools.relative_reward(tx["on_block"], address)
sign_tx = sign_transaction(tx["on_block"], address)
length = tools.local_get("length")
if len(sign_tx["jackpots"]) != tx["jackpots"]:
tools.log("wrong number of jackpots")
return False
if (
length - custom.long_time + custom.medium_time / 2 < tx["on_block"]
or length - custom.long_time - custom.medium_time / 2 > tx["on_block"]
):
tools.log("you did not wait the correct amount of time")
return False
if acc["secrets"][str(tx["on_block"])]["slashed"]:
tools.log("you were slashed, or you already claimed your reward at this height")
return False
if tx["amount"] != relative_reward + sign_tx["amount"]:
tools.log("reward wrong size")
return False
if sign_tx["secret_hash"] != tools.det_hash(tx["reveal"]):
tools.log("entropy+salt does not match")
return False
if tx["reveal"]["entropy"] not in [0, 1]:
tools.log("entropy must be either 0 or 1")
return False
return True
开发者ID:jtremback,项目名称:FlyingFox,代码行数:28,代码来源:transactions.py
示例9: spend_verify
def spend_verify(tx, txs, DB):
def sigs_match(sigs, pubs, msg):
return all(tools.verify(msg, sig, pub) for sig in sigs for pub in pubs)
tx_copy = copy.deepcopy(tx)
tx_copy_2 = copy.deepcopy(tx)
tx_copy.pop('signatures')
if len(tx['pubkeys']) == 0:
return False
if len(tx['signatures']) > len(tx['pubkeys']):
return False
msg = tools.det_hash(tx_copy)
if not sigs_match(copy.deepcopy(tx['signatures']),
copy.deepcopy(tx['pubkeys']), msg):
return False
if tx['amount'] < custom.fee:
return False
address = addr(tx_copy_2)
total_cost = 0
for Tx in filter(lambda t: address == addr(t), [tx] + txs):
if Tx['type'] == 'spend':
total_cost += Tx['amount']
if Tx['type'] == 'mint':
total_cost -= custom.block_reward
return int(blockchain.db_get(address, DB)['amount']) >= total_cost
开发者ID:Roasbeef,项目名称:basiccoin,代码行数:26,代码来源:transactions.py
示例10: spend_verify
def spend_verify(tx, txs, DB):
tx_copy=copy.copy(tx)
tx_copy.pop('signature')
if not pt.ecdsa_verify(tools.det_hash(tx_copy), tx['signature'], tx['id']): return False
if tx['amount']<custom.fee: return False
if int(blockchain.db_get(tx['id'], DB)['amount'])<int(tx['amount']): return False
return True
开发者ID:aneilbaboo,项目名称:basiccoin,代码行数:7,代码来源:transactions.py
示例11: reveal_jury_vote_check
def reveal_jury_vote_check(tx, txs, out, DB):
if not transactions.signature_check(tx):
out[0]+='signature check'
return False
address=addr(tx)
acc=tools.db_get(address, DB)
if not E_check(tx, 'decision_id', [str, unicode]):
out[0]+='decision id error'
return False
if is_number(tx['decision_id']):
out[0]+='that can not be a number'
return False
decision=tools.db_get(tx['decision_id'], DB)
if decision['state']!='proposed':
out[0]+='this decision has already been decided'
return False
if not E_check(tx, 'old_vote', [str, unicode]): return False
if not E_check(tx, 'secret', [str, unicode]): return False
if not E_check(tx, 'new_vote', [str, unicode]):
out[0]+='new vote error'
return False
if tx['decision_id'] not in acc['votes']:
out[0]+='decision id not in acc[votes] error'
return False
answer_hash=acc['votes'][tx['decision_id']]
if not answer_hash==tools.det_hash([tx['new_vote'], tx['secret']]):
out[0]+='hash does not match'
return False
if not E_check(tx, 'old_vote', [str, unicode]):
out[0]+='old vote does not exist error'
return False
if not txs_tools.fee_check(tx, txs, DB): return False
return True
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:33,代码来源:txs_truthcoin.py
示例12: reward_verify
def reward_verify(tx, txs, out, DB):
address=tools.addr(tx)
acc=tools.db_get(address)
relative_reward=tools.relative_reward(tx['on_block'], address)
sign_tx=sign_transaction(tx['on_block'], address)
length=tools.local_get('length')
if len(sign_tx['jackpots'])!=tx['jackpots']:
tools.log('wrong number of jackpots')
return False
if length-custom.long_time+custom.medium_time/2<tx['on_block']or length-custom.long_time-custom.medium_time/2>tx['on_block']:
tools.log('you did not wait the correct amount of time')
return False
if acc['secrets'][str(tx['on_block'])]['slashed']:
tools.log('you were slashed, or you already claimed your reward at this height')
return False
if tx['amount']!=relative_reward+sign_tx['amount']:
tools.log('reward wrong size')
return False
if sign_tx['secret_hash']!=tools.det_hash(tx['reveal']):
tools.log('entropy+salt does not match')
return False
if tx['reveal']['entropy'] not in [0,1]:
tools.log('entropy must be either 0 or 1')
return False
return True
开发者ID:appcoreopc,项目名称:slasher,代码行数:25,代码来源:transactions.py
示例13: insert_block
def insert_block(pubkey, rewarded_pubkey):
length = tools.db_get('length')
if length == -1:
# this is the first ever block
candidate_block = genesis(pubkey)
else:
# get the last block
prev_block = tools.db_get(length)
candidate_block = make_block(prev_block, tools.db_get('txs'), pubkey)
txs = copy.deepcopy(candidate_block['txs'])
flag = True
for tx in txs:
if tx['type'] == 'mint':
# no need to add reward
flag = False
if flag:
txs = txs + [make_mint(rewarded_pubkey)]
candidate_block['txs'] = txs
if tools.db_existence('privkey'):
privkey = tools.db_get('privkey')
else:
return 'no private key is known, so the tx cannot be signed. Here is the tx: \n' + str(
tools.package(txs).encode('base64').replace('\n', ''))
candidate_block['auth_sign'] = tools.sign(tools.det_hash(candidate_block), privkey)
candidate_block['auth_pubkey'] = pubkey
if candidate_block is None:
return
else:
custom.queues['suggested_blocks'].put(candidate_block)
开发者ID:coinami,项目名称:coinami-pro,代码行数:34,代码来源:miner.py
示例14: main
def main(c=0):
if type(c)==int:
p={'command':sys.argv[1:]}
else:
p={'command':c}
if len(p['command'])==0:
p['command'].append(' ')
c=p['command']
if c[0]=='make_PM':
tx=build_pm()
return run_command({'command':['pushtx', tools.package(tx).encode('base64')]})
elif c[0]=='buy_shares':
tx=build_buy_shares()
return run_command({'command':['pushtx', tools.package(tx).encode('base64')]})
elif c[0]=='start':
r=connect({'command':'blockcount'})
if is_off(r):
p=raw_input('what is your password?\n')
daemonize(lambda: threads.main(p))
else:
print('blockchain is already running')
elif c[0]=='new_address':
if len(c)<2:
print('what is your brain wallet? not enough inputs.')
else:
privkey=tools.det_hash(c[1])
pubkey=tools.privtopub(privkey)
address=tools.make_address([pubkey], 1)
return({'brain':str(c[1]),
'privkey':str(privkey),
'pubkey':str(pubkey),
'address':str(address)})
else:
return run_command(p)
开发者ID:BumblebeeBat,项目名称:FlyingFox,代码行数:34,代码来源:cli.py
示例15: home
def home(DB, dic):
if 'BrainWallet' in dic:
dic['privkey']=tools.det_hash(dic['BrainWallet'])
elif 'privkey' not in dic:
return "<p>You didn't type in your brain wallet.</p>"
privkey=dic['privkey']
pubkey=tools.privtopub(dic['privkey'])
address=tools.make_address([pubkey], 1)
if 'do' in dic.keys():
if dic['do']=='spend':
spend(float(dic['amount']), pubkey, privkey, dic['to'], DB)
out=empty_page
out=out.format('<p>your address: ' +str(address)+'</p>{}')
out=out.format('<p>current block: ' +str(DB['length'])+'</p>{}')
balance=blockchain.db_get(address, DB)['amount']
for tx in DB['txs']:
if tx['type'] == 'spend' and tx['to'] == address:
balance += tx['amount'] - custom.fee
if tx['type'] == 'spend' and tx['pubkeys'][0] == pubkey:
balance -= tx['amount']
out=out.format('<p>current balance is: ' +str(balance/100000.0)+'</p>{}')
if balance>0:
out=out.format(easyForm('/home', 'spend money', '''
<input type="hidden" name="do" value="spend">
<input type="text" name="to" value="address to give to">
<input type="text" name="amount" value="amount to spend">
<input type="hidden" name="privkey" value="{}">'''.format(privkey)))
txt=''' <input type="hidden" name="privkey" value="{}">'''
s=easyForm('/home', 'Refresh', txt.format(privkey))
return out.format(s)
开发者ID:Noelkd,项目名称:basiccoin,代码行数:30,代码来源:gui.py
示例16: easy_add_transaction
def easy_add_transaction(tx_orig, privkey='default'):
tx = copy.deepcopy(tx_orig)
if privkey in ['default', 'Default']:
if tools.db_existence('privkey'):
privkey = tools.db_get('privkey')
else:
return 'No private key is known, so the tx cannot be signed. '
pubkey = tools.privtopub(privkey)
address = tools.make_address([pubkey], 1)
if 'count' not in tx:
try:
tx['count'] = tools.count(address, {})
except:
tx['count'] = 1
# add our pubkey
if 'pubkeys' not in tx:
tx['pubkeys'] = [pubkey]
# this is IMPORTANT
# when adding new transaction which is signed by us,
# this procedure is applied. tx without signatures is signed with our privkey.
if 'signatures' not in tx:
tx['signatures'] = [tools.sign(tools.det_hash(tx), privkey)]
return blockchain.add_tx(tx)
开发者ID:coinami,项目名称:coinami-pro,代码行数:27,代码来源:api.py
示例17: sign
def sign(tx, privkey):
pubkey=tools.privtopub(privkey)
address=tools.make_address([pubkey], 1)
if 'pubkeys' not in tx:
tx['pubkeys']=[pubkey]
if 'signatures' not in tx:
tx['signatures']=[tools.sign(tools.det_hash(tx), privkey)]
return tx
开发者ID:appcoreopc,项目名称:slasher,代码行数:8,代码来源:api.py
示例18: sign
def sign(tx, privkey):
pubkey = tools.privtopub(privkey)
address = tools.make_address([pubkey], 1)
tx = add_recent_hash(tx)
if "pubkeys" not in tx:
tx["pubkeys"] = [pubkey]
if "signatures" not in tx:
tx["signatures"] = [tools.sign(tools.det_hash(tx), privkey)]
return tx
开发者ID:jtremback,项目名称:FlyingFox,代码行数:9,代码来源:api.py
示例19: easy_add_transaction
def easy_add_transaction(tx_orig, privkey, DB):
tx = copy.deepcopy(tx_orig)
pubkey = pt.privtopub(privkey)
try:
tx['count'] = blockchain.count(pubkey, DB)
except:
tx['count'] = 1
tx['signature'] = pt.ecdsa_sign(tools.det_hash(tx), privkey)
blockchain.add_tx(tx, DB)
开发者ID:wassname,项目名称:basiccoin,代码行数:9,代码来源:gui.py
示例20: POW
def POW(block, hashes):
halfHash = tools.det_hash(block)
block[u'nonce'] = random.randint(0, 100000000000000000)
count = 0
while tools.det_hash({u'nonce': block['nonce'],
u'halfHash': halfHash}) > block['target']:
count += 1
block[u'nonce'] += 1
if count > hashes:
return {'error': False}
if restart_signal.is_set():
restart_signal.clear()
return {'solution_found': True}
''' for testing sudden loss in hashpower from miners.
if block[u'length']>150:
else: time.sleep(0.01)
'''
return block
开发者ID:hanckmann,项目名称:basiccoin,代码行数:18,代码来源:consensus.py
注:本文中的tools.det_hash函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论