本文整理汇总了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)
示例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
示例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)
示例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()
示例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))))
示例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)