當前位置: 首頁>>代碼示例>>Python>>正文


Python DB.getUnspentOutputs方法代碼示例

本文整理匯總了Python中db.DB.getUnspentOutputs方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.getUnspentOutputs方法的具體用法?Python DB.getUnspentOutputs怎麽用?Python DB.getUnspentOutputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在db.DB的用法示例。


在下文中一共展示了DB.getUnspentOutputs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_input

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import getUnspentOutputs [as 別名]
  def add_input(self, inp):
    """ since inputs are really just outputs, this will be slowly converted to just accepting an input value
    and it finds previous output values from past transactions."""
    target_val = inp.value

    # find all previous unspent outputs....
    from db import DB
    db = DB()
    outputs = db.getUnspentOutputs(self.owner.publickey())

    if len(outputs) > 2:
      self.consolidateOutputs(outputs)
      outputs = db.getUnspentOutputs(self.owner.publickey())

    # find enough outputs to total the requested input...
    val = 0
    for o in outputs:
      val += o.value
      inp = Transaction.Input(o.value, o.transaction, o.n, owner=self.owner, output=o)
      self.input.append(inp)
      if val > target_val:
        break
    # compute change and create a new output to ourselves.
    diff = val - target_val

    if diff < 0:
      raise Exception('Output exceeds input!')
    # 'manually' add the change as an output back to ourselves
    o = Transaction.Output(diff, self.owner.publickey())
    self.output.append(o)
    o.n = len(self.output)

    return self
開發者ID:xran-deex,項目名稱:PyCoin,代碼行數:35,代碼來源:transaction.py

示例2: get_balance

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import getUnspentOutputs [as 別名]
 def get_balance(pubKey=None):
   from db import DB
   db = DB()
   if pubKey:
     unspent = db.getUnspentOutputs(pubKey)
   else:
     unspent = db.getUnspentOutputs(KeyStore.getPublicKey())
   balance = 0
   for o in unspent:
     balance += o.value
   return balance
開發者ID:plutokid,項目名稱:PyCoin,代碼行數:13,代碼來源:keystore.py

示例3: test_coinbase_transaction_with_2_transactions

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import getUnspentOutputs [as 別名]
 def test_coinbase_transaction_with_2_transactions(self):
   
   otherKey = RSA.generate(2048)
   
   # create a coinbase transaction, a regulat transaction and send the output to 'otherkey'
   
   t = Transaction()
   t.add_output(Transaction.Output(20, otherKey.publickey())) # give other 20
   t.finish_transaction()
   
   t.verify()
   
   # find all unspent outputs for ourselves and for other.
   db = DB()
   myKey = KeyStore.getPublicKey()
   myOuts = db.getUnspentOutputs(myKey)
   othersOuts = db.getUnspentOutputs(otherKey.publickey())
   
   self.assertEqual(myOuts[0].value, 80) # we should have 80 left
   self.assertEqual(othersOuts[0].value, 20) # other should have 20 now
開發者ID:plutokid,項目名稱:PyCoin,代碼行數:22,代碼來源:transaction_tests.py

示例4: verify

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import getUnspentOutputs [as 別名]
 def verify(self, debug=False):
   """ verifies all the inputs and outputs of this transaction """
   # find all previous unspent outputs....
   from db import DB
   db = DB()
   log.info('Verifying transaction...')
   if debug:
     self.display_debugging()
   if self.input[0].prev == bytes(struct.pack('I', 0) * 8):
     log.info('Coinbase transaction verified.')
     return True
   outputs = db.getUnspentOutputs()
   for o in outputs:
     for i in self.input:
       if i.prev == o.transaction and i.n == o.n:
         if not self.check_sig(i.signature, o.pubKey, o.transaction):
           log.warning('Transaction invalid!')
           return False
         log.debug('removing output...')
         db.removeUnspentOutput(o) # output was verified, remove it
   log.info('Regular transaction verified')
   if self.callback:
     self.callback()
   return True
開發者ID:xran-deex,項目名稱:PyCoin,代碼行數:26,代碼來源:transaction.py


注:本文中的db.DB.getUnspentOutputs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。