Il es déjà fait
De loin pas mon meilleurs code mais il fait sont affaire pour un code fait en 1H
#!/usr/bin/python
import json, requests, pprint , sys
pp = pprint.PrettyPrinter(indent=4)
COIN=1E8
addresse='1octE21wzrfBKbHVD9sdts8UvUA3CKYUm' #Addresse pour recevoir les paris
basebet=1000000
block_limit=519000 #Dernoer block pour parier
nbbetmax=100 #Nombre de paris maximum
pricewin=400.00 #Prix a trouver
rpcPort = 8332 #Port RPC
rpcUser = 'bitcoinrpc' #User RPC
rpcPassword = '' #Pass RPC
url = 'https://blockchain.info/fr/unspent?active=' + addresse #URL Transaction TXNO
serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort)
headers = {'content-type': 'application/json'}
resp = requests.get(url=url)
data = json.loads(resp.text)
refound_fee = {} #Dict pour le payement
def get_address(index):
url = 'https://blockchain.info/tx-index/' + str(index) + '?format=json'
resp = requests.get(url=url)
return json.loads(resp.text)
print("Lancement BlockMaxi:%d AmountBets:%.8fBTC NB_BetMax:%d Resultat:%.8f ADDR:%s" % ( block_limit , (float(basebet) / COIN) , nbbetmax , pricewin , addresse ))
addr_win = []
last_delta= 9999999999
nb_bet=0
total_bet=0
for tx in data['unspent_outputs']:
rfd = (int(tx['value']) - basebet ) ;
bet = float(rfd) / 100
previous = get_address( tx['tx_index'])
addr =previous['inputs'][0]['prev_out']['addr']
tx['tx_id']= previous['hash']
if int(previous['block_height']) > block_limit :
refound_fee[addr] = refound_fee.get(addr, 0) + (float(tx['value']) / COIN)
print("TX %s ADDR %s TooLate remboursement de %.8fmBTC" % ( tx['tx_hash'] , addr , (float(int(tx['value'])) / 100000) ))
continue
else:
nb_bet=nb_bet+1
if ( nb_bet > nbbetmax ):
print("Erreur plus de %d Bets relancer avec un block limit inferieur a %d" % ( nbbetmax , nb_bet , previous['block_height']))
sys.exit(1)
refound_fee[addr] = refound_fee.get(addr, 0) + (float(rfd) / COIN)
total_bet=total_bet + int(basebet)
delta=( bet - pricewin)
if delta < 0:
delta = delta * -1
if ( delta == last_delta ) :
addr_win.append(addr)
if ( delta < last_delta ) :
last_delta = delta
addr_win= [ addr ]
print("TX %s ADDR %s mise sur %f delta %f Euro remboursement de %.8fmBTC" % ( tx['tx_hash'] , addr , bet , delta , (float(rfd) / 100000) ))
total_win=(float( total_bet) / 100000000)
pp.pprint({ 'win': addr_win , 'total_win' : total_win})
for win in addr_win:
print("Addresse:%s Win:%.8fBTC" % ( win , total_win))
refound_fee[win] = refound_fee[win] + total_win
print("Liste du Payout")
pp.pprint(refound_fee)
spend=[]
for tx in data['unspent_outputs']:
spend.append({ 'txid' : tx['tx_id'] , 'vout' : tx['tx_output_n'] })
print("Creation de la transaction")
payload = json.dumps({"method": 'createrawtransaction', "params": [ spend , refound_fee], "jsonrpc": "2.0"})
response = requests.get(serverURL, headers=headers, data=payload)
print(response.json()['result'],response.json()['error'])
transaction=(response.json()['result'])
print("Signature de la transaction")
payload = json.dumps({"method": 'signrawtransaction', "params": [ transaction ] , "jsonrpc": "2.0"})
response = requests.get(serverURL, headers=headers, data=payload)
print(response.json()['result'],response.json()['error'])