Exemple #1
0
class Cashier:
    _exchanges = exchanges.actived_exchanges 

    def __init__(self):
        self.wallet = Wallet()
        self.qty_per_order = config.configuration['qty_per_order']

    def post_transfers(self, buy_account, sell_account):
        '''交易完成以后的比特币转账
        流程:
        1. 检查钱包是否有足够余额
            2.1 有余额则先发送比特币给卖方
        2. 买方转移比特币到钱包        
        '''
        buy_ex = Trader._exchanges[buy_account.name]
        sell_ex = Trader._exchanges[sell_account.name]
        wallet_balance = self.wallet.balance()
        if wallet_balance > self.qty_per_order:
            self.wallet.withdraw(sell_account.stock_deposit_address, self.qty_per_order)
        buy_ex.withdraw_stock(self.qty_per_order)            

    def make_balance(self, accounts):
        wallet_balance = self.wallet.balance()        
        for a in accounts:
            if a.stock_balance < self.qty_per_order and wallet_balance > self.qty_per_order:
                _logger.info('[CASHIER]\t\t Transfering BTC from wallet to account "{0}", qty={1}'
                        .format(a.name, self.qty_per_order))
                self.wallet.withdraw(a.stock_deposit_address, self.qty_per_order)
                wallet_balance -= self.qty_per_order
Exemple #2
0
def test_deposit():

    from pysolcrypto.altbn128 import randsn, FQ, multiply as ecmul, add as ecadd
    contract = ZKToken.deploy(web3, n)
    wallet = Wallet('Alice', contract)
    value = 3.0
    receipt = wallet.deposit(value)
    bal = wallet.balance()
    assert bal == value
Exemple #3
0
 def ask_double_down(self):			#ask player if he wishes to double down
  self.status=''
  while (self.status!='YES' and self.status!='NO'):
   print(self.name,end=', ')
   self.status=input('Do you wish to double your bet?, Yes or No?\n').upper()
  if self.status=='YES':
   if Wallet.balance(self) < self.bet:		#if wallet balance is insufficient
    print('Your balance is low.Add money to your casino wallet')
    recharge=''
    while not (recharge.isdigit() and eval(recharge)>=self.bet):      #recharge atleast to double the bet
     recharge=input('Enter money atleast sufficient to recharge your casino wallet\n')
    print('Recharging...')
    Wallet.deposit(self,eval(recharge))         #recharging
   Wallet.withdraw(self,self.bet)		#withdraw another bet(for double down)
   self.change_status("DD")				#change status to DD(double down)
  else:
   self.change_status=("NDD")				#change status to NDD(no double down)
Exemple #4
0
 def ask_for_insurance(self):							#to ask if player needs to insure or not.
  self.status=''
  while self.status!='YES' and self.status!='NO':
   print(self.name,',do you want to insure yourself? Yes or No?')
   self.status=input().upper()
   print()
  if self.status=='YES':
   if Wallet.balance(self)< self.bet/2:			#if wallet balance is insufficient
    print('Your balance is low.Add money to your casino wallet')
    recharge=''
    while not (recharge.isdigit() and eval(recharge)>=self.bet/2):	#recharge atleast to take this insurance
     recharge=input('Enter money atleast sufficient to recharge your casino wallet\n')
    print('\nRecharging...')
    Wallet.deposit(self,eval(recharge))		#recharging
   Wallet.withdraw(self,self.bet/2)			#withdrawing insurance amount
   self.change_status('INSURE')
  else:
   self.change_status('NOINSURE')
Exemple #5
0
 def ask_split(self):			#check and ask the player if he wish to split pair
  while (self.status!='YES' and self.status!='NO'):
   print(self.name,end=', ')
   self.status=input('Do you wish to split?, Yes or No?\n').upper()
  if self.status=='YES':
   if Wallet.balance(self)< self.bet:			#if wallet balance is insufficient
    print('Your balance is low.Add money to your casino wallet')
    recharge=''
    while not (recharge.isdigit() and eval(recharge)>=self.bet):	#recharge atleast to split
     recharge=input('Enter money atleast sufficient to recharge your casino wallet\n')
    print('Recharging...')
    Wallet.deposit(self,eval(recharge))         #recharging
   Wallet.withdraw(self,self.bet)                     #withdrawing split amount
   self.change_status('SPLIT')			#change status to "SPLIT"
   self.cards_split=[self.cards[0]]		#another hand
   self.status_split='SPLIT'			#assigning status of another hand as "PLAY"
   self.add_split=0				#assigning add of another hand as 0
   self.cards=[self.cards[0]]			#removing second element
  else:
   self.change_status('NOSPLIT')
Exemple #6
0
def test_confidential_transaction():
    from pysolcrypto.altbn128 import randsn, FQ, multiply as ecmul, add as ecadd

    print('bit size: ' + str(n))
    contract = ZKToken.deploy(web3, n)

    # setup phase
    wallet_alice = Wallet('Alice', contract, notes=[], composer=None)
    gas_receipt = wallet_alice.quick_setup(NaiveStrategy)
    print('\nAlice setup\n' + gas_receipt)
    wallet_bob = Wallet('Bob', contract, notes=[], composer=None)
    print('\nBob setup\n' + gas_receipt)
    gas_receipt = wallet_bob.quick_setup(NaiveStrategy)

    # deposit
    receipt = wallet_alice.deposit(3.0)
    print('\nAlice is to deposit 3 eth' + '\ngas cost: ' +
          str(receipt.gasUsed))
    receipt = wallet_alice.deposit(8.0)
    print('\nAlice is to deposit 8 eth' + '\ngas cost: ' +
          str(receipt.gasUsed))
    print('\nbalances ' + '\nAlice: ' + str(wallet_alice.balance()) + ' eth' +
          '\nBob: ' + str(wallet_bob.balance()) + ' eth' + '\nContract: ' +
          str(Web3.fromWei(web3.eth.getBalance(contract.address), 'ether')) +
          ' eth')
    print('\nAlice is to send 10 eth to Bob')

    # transaction
    tx = wallet_alice.make_ct_phase_1(10.0)
    tx = wallet_bob.make_ct_phase_2(tx)
    receipt = tx.broadcast()
    print('2 input, 2 output transaction' + '\ngas cost: ' +
          str(receipt.gasUsed))
    for input in tx.inputs_of('Alice'):
        assert contract.get_note(input) == 0
    for output in tx.outputs_of('Alice'):
        note = Commitment.aggregate(
            [wallet_alice.get_commitment(index) for index in output])
        assert note.y() == contract.get_note(note.x())
    for output in tx.outputs_of('Bob'):
        note = Commitment.aggregate(
            [wallet_bob.get_commitment(index) for index in output])
        assert note.y() == contract.get_note(note.x())
    wallet_alice.update(tx)
    wallet_bob.update(tx)
    print('\nbalances ' + '\nAlice: ' + str(wallet_alice.balance()) + ' eth' +
          '\nBob: ' + str(wallet_bob.balance()) + ' eth' + '\nContract: ' +
          str(Web3.fromWei(web3.eth.getBalance(contract.address), 'ether')) +
          ' eth')

    # withdraw
    receiver = Web3.toChecksumAddress(
        Web3.toHex(Web3.sha3(random.randint(1, 44000))[-20:]))
    receipt = wallet_bob.withdraw(4.0, receiver)
    print('\nBob withdraws 4 eth' + '\ngas cost: ' + str(receipt.gasUsed))
    assert Web3.toWei(4.0, 'ether') == web3.eth.getBalance(receiver)
    print('\nbalances ' + '\nAlice: ' + str(wallet_alice.balance()) + ' eth' +
          '\nBob: ' + str(wallet_bob.balance()) + ' eth' + '\nContract: ' +
          str(Web3.fromWei(web3.eth.getBalance(contract.address), 'ether')) +
          ' eth' + '\nReceiver of the withdrawal: ' +
          str(Web3.fromWei(web3.eth.getBalance(receiver), 'ether')) + ' eth')
    print()
    print('fin')