本文整理了Java中org.bitcoinj.core.Utils.decodeCompactBits()
方法的一些代码示例,展示了Utils.decodeCompactBits()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.decodeCompactBits()
方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:decodeCompactBits
[英]The "compact" format is a representation of a whole number N using an unsigned 32 bit number similar to a floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can be thought of as "number of bytes of N". The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents the sign of N. Therefore, N = (-1^sign) * mantissa * 256^(exponent-3).
Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn(). MPI uses the most significant bit of the first byte as sign. Thus 0x1234560000 is compact 0x05123456 and 0xc0de000000 is compact 0x0600c0de. Compact 0x05c0de00 would be -0x40de000000.
Bitcoin only uses this "compact" format for encoding difficulty targets, which are unsigned 256bit quantities. Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident.
[中]“紧凑”格式是使用类似于浮点格式的无符号32位数字表示整数N。最高有效8位是以256为底的无符号指数。这个指数可以被认为是“N的字节数”。下23位是尾数。第24位(0x800000)表示N的符号。因此,N=(-1^符号)尾数256^(指数-3)。
Satoshi最初的实现使用了BN_bn2mpi()和BN_mpi2bn()。MPI使用第一个字节的最高有效位作为符号。因此0x123456000是紧凑的0x05123456,0xc0de000000是紧凑的0x0600c0de。紧凑型0x05c0de00将是-0x40de000000。
比特币仅使用这种“紧凑”格式对难度目标进行编码,这些目标是无符号的256比特量。因此,符号位和使用base 256的所有复杂性可能都是实现意外。
代码示例来源:origin: dogecoin/libdohj
public AbstractLitecoinParams() {
super();
interval = LITE_INTERVAL;
targetTimespan = LITE_TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL);
packetMagic = 0xfbc0b6db;
bip32HeaderPub = 0x0488C42E; //The 4 byte header that serializes in base58 to "xpub". (?)
bip32HeaderPriv = 0x0488E1F4; //The 4 byte header that serializes in base58 to "xprv" (?)
}
代码示例来源:origin: greenaddress/GreenBits
/**
* Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the
* target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception
* is thrown.
*/
public BigInteger getDifficultyTargetAsInteger() throws VerificationException {
BigInteger target = Utils.decodeCompactBits(difficultyTarget);
if (target.signum() <= 0 || target.compareTo(params.maxTarget) > 0)
throw new VerificationException("Difficulty target is bad: " + target.toString());
return target;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the
* target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception
* is thrown.
*/
public BigInteger getDifficultyTargetAsInteger() throws VerificationException {
BigInteger target = Utils.decodeCompactBits(difficultyTarget);
if (target.signum() <= 0 || target.compareTo(params.maxTarget) > 0)
throw new VerificationException("Difficulty target is bad: " + target.toString());
return target;
}
代码示例来源:origin: HashEngineering/dashj
/**
* Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the
* target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception
* is thrown.
*/
public BigInteger getDifficultyTargetAsInteger() throws VerificationException {
BigInteger target = Utils.decodeCompactBits(difficultyTarget);
if (target.signum() <= 0 || target.compareTo(params.maxTarget) > 0)
throw new VerificationException("Difficulty target is bad: " + target.toString());
return target;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the
* target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception
* is thrown.
*/
public BigInteger getDifficultyTargetAsInteger() throws VerificationException {
BigInteger target = Utils.decodeCompactBits(difficultyTarget);
if (target.signum() <= 0 || target.compareTo(params.maxTarget) > 0)
throw new VerificationException("Difficulty target is bad: " + target.toString());
return target;
}
代码示例来源:origin: dogecoin/libdohj
public AbstractNamecoinParams() {
super();
genesisBlock = createGenesis(this);
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL); // TODO: figure out the Namecoin value of this
// BIP 43 recommends using these values regardless of which blockchain is in use.
bip32HeaderPub = 0x0488B21E; //The 4 byte header that serializes in base58 to "xpub".
bip32HeaderPriv = 0x0488ADE4; //The 4 byte header that serializes in base58 to "xprv"
}
代码示例来源:origin: dogecoin/libdohj
public AbstractDogecoinParams(final int setDiffChangeTarget) {
super();
genesisBlock = createGenesis(this);
interval = DOGE_INTERVAL;
newInterval = DOGE_INTERVAL_NEW;
targetTimespan = DOGE_TARGET_TIMESPAN;
newTargetTimespan = DOGE_TARGET_TIMESPAN_NEW;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL);
diffChangeTarget = setDiffChangeTarget;
packetMagic = 0xc0c0c0c0;
bip32HeaderPub = 0x0488C42E; //The 4 byte header that serializes in base58 to "xpub". (?)
bip32HeaderPriv = 0x0488E1F4; //The 4 byte header that serializes in base58 to "xprv" (?)
}
代码示例来源:origin: dogecoin/libdohj
BigInteger newTarget = Utils.decodeCompactBits(lastDifficultyTarget);
newTarget = newTarget.multiply(BigInteger.valueOf(actualTime));
newTarget = newTarget.divide(BigInteger.valueOf(retargetTimespan));
代码示例来源:origin: dogecoin/libdohj
public LitecoinTestNet3Params() {
super();
id = ID_LITE_TESTNET;
// Genesis hash is f5ae71e26c74beacc88382716aced69cddf3dffff24f384e1808905e0188f68f
packetMagic = 0xfcc1b7dc;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL);
port = 19333;
addressHeader = 111;
p2shHeader = 196;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
dumpedPrivateKeyHeader = 239;
this.genesisBlock = createGenesis(this);
spendableCoinbaseDepth = 30;
subsidyDecreaseBlockCount = 100000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("f5ae71e26c74beacc88382716aced69cddf3dffff24f384e1808905e0188f68f"));
alertSigningKey = Hex.decode("0449623fc74489a947c4b15d579115591add020e53b3490bf47297dfa3762250625f8ecc2fb4fc59f69bdce8f7080f3167808276ed2c79d297054367566038aa82");
majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = TESTNET_MAJORITY_WINDOW;
dnsSeeds = new String[] {
"testnet-seed.litecointools.com",
"testnet-seed.ltc.xurious.com",
"dnsseed.wemine-testnet.com"
};
bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394;
}
代码示例来源:origin: dogecoin/libdohj
public LitecoinMainNetParams() {
super();
id = ID_LITE_MAINNET;
// Genesis hash is 12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2
packetMagic = 0xfbc0b6db;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL);
port = 9333;
addressHeader = 48;
p2shHeader = 5;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
dumpedPrivateKeyHeader = 176;
this.genesisBlock = createGenesis(this);
spendableCoinbaseDepth = 100;
subsidyDecreaseBlockCount = 840000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"));
alertSigningKey = Hex.decode("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9");
majorityEnforceBlockUpgrade = MAINNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = MAINNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = MAINNET_MAJORITY_WINDOW;
dnsSeeds = new String[] {
"dnsseed.litecointools.com",
"dnsseed.litecoinpool.org",
"dnsseed.ltc.xurious.com",
"dnsseed.koin-project.com",
"dnsseed.weminemnc.com"
};
bip32HeaderPub = 0x0488B21E;
bip32HeaderPriv = 0x0488ADE4;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d00ffffL);
port = 18333;
addressHeader = 111;
代码示例来源:origin: greenaddress/GreenBits
public TestNet2Params() {
super();
id = ID_TESTNET;
packetMagic = 0xfabfb5daL;
port = 18333;
addressHeader = 111;
p2shHeader = 196;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d0fffffL);
dumpedPrivateKeyHeader = 239;
genesisBlock.setTime(1296688602L);
genesisBlock.setDifficultyTarget(0x1d07fff8L);
genesisBlock.setNonce(384568319);
spendableCoinbaseDepth = 100;
subsidyDecreaseBlockCount = 210000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
dnsSeeds = null;
addrSeeds = null;
bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394;
majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = TESTNET_MAJORITY_WINDOW;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
public TestNet2Params() {
super();
id = ID_TESTNET;
packetMagic = 0xfabfb5daL;
port = 18333;
addressHeader = 111;
p2shHeader = 196;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d0fffffL);
dumpedPrivateKeyHeader = 239;
genesisBlock.setTime(1296688602L);
genesisBlock.setDifficultyTarget(0x1d07fff8L);
genesisBlock.setNonce(384568319);
spendableCoinbaseDepth = 100;
subsidyDecreaseBlockCount = 210000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
dnsSeeds = null;
addrSeeds = null;
bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394;
majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = TESTNET_MAJORITY_WINDOW;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
public TestNet2Params() {
super();
id = ID_TESTNET;
packetMagic = 0xdab5bffaL;
port = 18333;
addressHeader = 111;
p2shHeader = 196;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d0fffffL);
dumpedPrivateKeyHeader = 239;
genesisBlock.setTime(1296688602L);
genesisBlock.setDifficultyTarget(0x1d07fff8L);
genesisBlock.setNonce(384568319);
spendableCoinbaseDepth = 100;
subsidyDecreaseBlockCount = 210000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
dnsSeeds = null;
addrSeeds = null;
bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394;
majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = TESTNET_MAJORITY_WINDOW;
/** Activation time at which the cash HF kicks in. */
cashHardForkActivationTime = 1510600000;
daaHeight = 1188697;
}
代码示例来源:origin: greenaddress/GreenBits
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d00ffffL);
port = 18333;
addressHeader = 111;
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
interval = INTERVAL;
targetTimespan = TARGET_TIMESPAN;
maxTarget = Utils.decodeCompactBits(0x1d00ffffL);
port = 18333;
addressHeader = 111;
代码示例来源:origin: dogecoin/libdohj
public DogecoinTestNet3Params() {
super(DIFFICULTY_CHANGE_TARGET);
id = ID_DOGE_TESTNET;
packetMagic = 0xfcc1b7dc;
maxTarget = Utils.decodeCompactBits(0x1e0fffffL);
port = 44556;
addressHeader = 113;
p2shHeader = 196;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
dumpedPrivateKeyHeader = 241;
genesisBlock.setTime(1391503289L);
genesisBlock.setDifficultyTarget(0x1e0ffff0L);
genesisBlock.setNonce(997879);
spendableCoinbaseDepth = 30;
subsidyDecreaseBlockCount = 100000;
String genesisHash = genesisBlock.getHashAsString();
checkState(genesisHash.equals("bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e"));
alertSigningKey = Hex.decode("042756726da3c7ef515d89212ee1705023d14be389e25fe15611585661b9a20021908b2b80a3c7200a0139dd2b26946606aab0eef9aa7689a6dc2c7eee237fa834");
majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
majorityWindow = TESTNET_MAJORITY_WINDOW;
dnsSeeds = new String[] {
"testseed.jrn.me.uk"
};
// Note this is the same as the BIP32 testnet, as BIP44 makes HD wallets
// chain agnostic. Dogecoin mainnet has its own headers for legacy reasons.
bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394;
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void compactEncoding() throws Exception {
assertEquals(new BigInteger("1234560000", 16), Utils.decodeCompactBits(0x05123456L));
assertEquals(new BigInteger("c0de000000", 16), Utils.decodeCompactBits(0x0600c0de));
assertEquals(0x05123456L, Utils.encodeCompactBits(new BigInteger("1234560000", 16)));
assertEquals(0x0600c0deL, Utils.encodeCompactBits(new BigInteger("c0de000000", 16)));
}
代码示例来源:origin: fr.acinq/bitcoinj-core
timespan = targetTimespan * 4;
BigInteger newTarget = Utils.decodeCompactBits(prev.getDifficultyTarget());
newTarget = newTarget.multiply(BigInteger.valueOf(timespan));
newTarget = newTarget.divide(BigInteger.valueOf(targetTimespan));
代码示例来源:origin: HashEngineering/dashj
timespan = targetTimespan * 4;
BigInteger newTarget = Utils.decodeCompactBits(prev.getDifficultyTarget());
newTarget = newTarget.multiply(BigInteger.valueOf(timespan));
newTarget = newTarget.divide(BigInteger.valueOf(targetTimespan));
内容来源于网络,如有侵权,请联系作者删除!