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


Python Uint256.from_bignum方法代碼示例

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


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

示例1: retarget

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
def retarget(time_2weekago, 
             time_now, 
             target_timespan,
             current_target, # compact format
             proof_of_work_limit):
    actual_timespan = time_now - time_2weekago
    # Limit adjustment step
    if actual_timespan < target_timespan/4:
        actual_timespan = target_timespan/4;
    if actual_timespan > target_timespan*4:
        actual_timespan = target_timespan*4;
    # Retarget
    new_target = Uint256.from_bignum(uint256_difficulty(current_target).get_bignum() * actual_timespan / target_timespan)
    if new_target > proof_of_work_limit:
        new_target = proof_of_work_limit
    return compact_difficulty(new_target)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:18,代碼來源:bockchain_work.py

示例2: test_compact_difficulty

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
 def test_compact_difficulty(self):
     value = compact_difficulty(Uint256.from_bignum(0x00000000FFFF0000000000000000000000000000000000000000000000000000))
     assert value == 0x1d00ffff
     value = compact_difficulty(Uint256.from_bignum(0x00000000000404cb000000000000000000000000000000000000000000000000))
     assert value == 0x1b0404cb
開發者ID:sirk390,項目名稱:coinpy,代碼行數:7,代碼來源:test_difficulty.py

示例3: test_uint256_difficulty

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
 def test_uint256_difficulty(self):
     value = uint256_difficulty(0x1d00ffff)
     assert value == Uint256.from_bignum(0x00000000FFFF0000000000000000000000000000000000000000000000000000)
     value = uint256_difficulty(0x1b0404cb)
     assert value == Uint256.from_bignum(0x00000000000404cb000000000000000000000000000000000000000000000000)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:7,代碼來源:test_difficulty.py

示例4: TestDifficulty

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
import unittest
from coinpy.lib.blocks.difficulty import uint256_difficulty, compact_difficulty
from coinpy.model.protocol.structures.uint256 import Uint256

class TestDifficulty(unittest.TestCase):
    def setUp(self):
        pass
    
    def test_compact_difficulty(self):
        value = compact_difficulty(Uint256.from_bignum(0x00000000FFFF0000000000000000000000000000000000000000000000000000))
        assert value == 0x1d00ffff
        value = compact_difficulty(Uint256.from_bignum(0x00000000000404cb000000000000000000000000000000000000000000000000))
        assert value == 0x1b0404cb
        
    def test_uint256_difficulty(self):
        value = uint256_difficulty(0x1d00ffff)
        assert value == Uint256.from_bignum(0x00000000FFFF0000000000000000000000000000000000000000000000000000)
        value = uint256_difficulty(0x1b0404cb)
        assert value == Uint256.from_bignum(0x00000000000404cb000000000000000000000000000000000000000000000000)
        
if __name__ == '__main__':
    value = compact_difficulty(Uint256.from_bignum(0x00000000FFFF0000000000000000000000000000000000000000000000000000))
    #print value
    #print 0x1d00ffff
    unittest.main()
    
開發者ID:sirk390,項目名稱:coinpy,代碼行數:27,代碼來源:test_difficulty.py

示例5: uint256_difficulty

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
def uint256_difficulty(bits):
    exp, value = bits >> 24, bits & 0xFFFFFF
    return (Uint256.from_bignum(value * 2 ** (8 * (exp - 3))))
開發者ID:sirk390,項目名稱:coinpy,代碼行數:5,代碼來源:difficulty.py

示例6: is_money_range

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bignum [as 別名]
COIN = 100000000
CENT = 1000000
MAX_MONEY = 21000000 * COIN

TARGET_TIMESPAN =  14 * 24 * 60 * 60 # 2 weeks
TARGET_SPACING = 10 * 60 # 10 minutes
TARGET_INTERVAL = TARGET_TIMESPAN / TARGET_SPACING #  2016 blocks / 2weeks

# block_time must be larger than the median of past "MEDIAN_TIME_SPAN" block_time's.
MEDIAN_TIME_SPAN=11

# when smaller, locktime is treated as a blockheight, otherwise as a blocktime
LOCKTIME_THRESHOLD = 500000000; # Tue Nov  5 00:53:20 1985 UTC


COINBASE_MATURITY=100
CONFIRMATIONS=6

MAX_BLOCK_SIZE = 1000000
#MAX_BLOCK_SIZE


PROOF_OF_WORK_LIMIT = {MAIN:     Uint256.from_bignum((1 << (256 - 32)) - 1), #~uint256(0) >> 32
                       TESTNET : Uint256.from_bignum((1 << (256 - 28)) - 1),
                       TESTNET3 : Uint256.from_bignum((1 << (256 - 28)) - 1),
                       UNITNET: Uint256.from_bignum((1 << (256 - 10)) - 1)}

def is_money_range(value):
    return (value >= 0 and value <= MAX_MONEY)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:31,代碼來源:bitcoin.py


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