当前位置: 首页>>代码示例>>Java>>正文


Java BigIntegers类代码示例

本文整理汇总了Java中org.spongycastle.util.BigIntegers的典型用法代码示例。如果您正苦于以下问题:Java BigIntegers类的具体用法?Java BigIntegers怎么用?Java BigIntegers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BigIntegers类属于org.spongycastle.util包,在下文中一共展示了BigIntegers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sign

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
private void sign() {
    flags |= SIGNATURE_FLAG;
    byte[] forSig = hash();

    ECKey.ECDSASignature signature = from.sign(forSig);

    byte v;

    if (signature.v == 27) v = 0;
    else if (signature.v == 28) v = 1;
    else throw new RuntimeException("Invalid signature: " + signature);

    this.signature =
            ByteUtil.merge(BigIntegers.asUnsignedByteArray(32, signature.r),
                    BigIntegers.asUnsignedByteArray(32, signature.s), new byte[]{v});
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:17,代码来源:WhisperMessage.java

示例2: validate

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
private void validate() {
    if (getNonce().length > HASH_LENGTH) throw new RuntimeException("Nonce is not valid");
    if (receiveAddress != null && receiveAddress.length != 0 && receiveAddress.length != ADDRESS_LENGTH)
        throw new RuntimeException("Receive address is not valid");
    if (gasLimit.length > HASH_LENGTH)
        throw new RuntimeException("Gas Limit is not valid");
    if (gasPrice != null && gasPrice.length > HASH_LENGTH)
        throw new RuntimeException("Gas Price is not valid");
    if (value != null  && value.length > HASH_LENGTH)
        throw new RuntimeException("Value is not valid");
    if (getSignature() != null) {
        if (BigIntegers.asUnsignedByteArray(signature.r).length > HASH_LENGTH)
            throw new RuntimeException("Signature R is not valid");
        if (BigIntegers.asUnsignedByteArray(signature.s).length > HASH_LENGTH)
            throw new RuntimeException("Signature S is not valid");
        if (getSender() != null && getSender().length != ADDRESS_LENGTH)
            throw new RuntimeException("Sender is not valid");
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:20,代码来源:Transaction.java

示例3: toString

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public String toString(int maxDataSize) {
    rlpParse();
    String dataS;
    if (data == null) {
        dataS = "";
    } else if (data.length < maxDataSize) {
        dataS = ByteUtil.toHexString(data);
    } else {
        dataS = ByteUtil.toHexString(Arrays.copyOfRange(data, 0, maxDataSize)) +
                "... (" + data.length + " bytes)";
    }
    return "TransactionData [" + "hash=" + ByteUtil.toHexString(hash) +
            "  nonce=" + ByteUtil.toHexString(nonce) +
            ", gasPrice=" + ByteUtil.toHexString(gasPrice) +
            ", gas=" + ByteUtil.toHexString(gasLimit) +
            ", receiveAddress=" + ByteUtil.toHexString(receiveAddress) +
            ", sendAddress=" + ByteUtil.toHexString(getSender()) +
            ", value=" + ByteUtil.toHexString(value) +
            ", data=" + dataS +
            ", signatureV=" + (signature == null ? "" : signature.v) +
            ", signatureR=" + (signature == null ? "" : ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r))) +
            ", signatureS=" + (signature == null ? "" : ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s))) +
            "]";
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:25,代码来源:Transaction.java

示例4: Env

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public Env(JSONObject env) {

        String coinbase = env.get("currentCoinbase").toString();
        String difficulty = env.get("currentDifficulty").toString();
        String timestamp = env.get("currentTimestamp").toString();
        String number = env.get("currentNumber").toString();
        String gasLimit = Utils.parseUnidentifiedBase(env.get("currentGasLimit").toString());
        Object previousHash = env.get("previousHash");
        String prevHash = previousHash == null ? "" : previousHash.toString();

        this.currentCoinbase = Utils.parseData(coinbase);
        this.currentDifficulty = BigIntegers.asUnsignedByteArray(TestCase.toBigInt(difficulty) );
        this.currentGasLimit =   BigIntegers.asUnsignedByteArray(TestCase.toBigInt(gasLimit));
        this.currentNumber = TestCase.toBigInt(number).toByteArray();
        this.currentTimestamp = TestCase.toBigInt(timestamp).toByteArray();
        this.previousHash = Utils.parseData(prevHash);

    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:Env.java

示例5: testTransactionFromUnsignedRLP

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
@Ignore
@Test
public void testTransactionFromUnsignedRLP() throws Exception {
    Transaction txUnsigned = new Transaction(Hex.decode(RLP_ENCODED_UNSIGNED_TX));

    assertEquals(HASH_TX, Hex.toHexString(txUnsigned.getHash()));
    assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));
    txUnsigned.sign(ECKey.fromPrivate(Hex.decode(KEY)));
    assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));

    assertEquals(BigInteger.ZERO, new BigInteger(1, txUnsigned.getNonce()));
    assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txUnsigned.getGasPrice()));
    assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txUnsigned.getGasLimit()));
    assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txUnsigned.getReceiveAddress()));
    assertEquals(new BigInteger(1, testValue), new BigInteger(1, txUnsigned.getValue()));
    assertNull(txUnsigned.getData());
    assertEquals(27, txUnsigned.getSignature().v);
    assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().r)));
    assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().s)));
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:TransactionTest.java

示例6: testTransactionFromSignedRLP

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
@Ignore
@Test
public void testTransactionFromSignedRLP() throws Exception {
    Transaction txSigned = new Transaction(Hex.decode(RLP_ENCODED_SIGNED_TX));

    assertEquals(HASH_TX, Hex.toHexString(txSigned.getHash()));
    assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txSigned.getEncoded()));

    assertEquals(BigInteger.ZERO, new BigInteger(1, txSigned.getNonce()));
    assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txSigned.getGasPrice()));
    assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txSigned.getGasLimit()));
    assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txSigned.getReceiveAddress()));
    assertEquals(new BigInteger(1, testValue), new BigInteger(1, txSigned.getValue()));
    assertNull(txSigned.getData());
    assertEquals(27, txSigned.getSignature().v);
    assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().r)));
    assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().s)));
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:19,代码来源:TransactionTest.java

示例7: testTransactionFromNew1

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
@Ignore
@Test
public void testTransactionFromNew1() throws MissingPrivateKeyException {
    Transaction txNew = new Transaction(testNonce, testGasPrice, testGasLimit, testReceiveAddress, testValue, testData);

    assertEquals("", Hex.toHexString(txNew.getNonce()));
    assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txNew.getGasPrice()));
    assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txNew.getGasLimit()));
    assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txNew.getReceiveAddress()));
    assertEquals(new BigInteger(1, testValue), new BigInteger(1, txNew.getValue()));
    assertEquals("", Hex.toHexString(txNew.getData()));
    assertNull(txNew.getSignature());

    assertEquals(RLP_ENCODED_RAW_TX, Hex.toHexString(txNew.getEncodedRaw()));
    assertEquals(HASH_TX, Hex.toHexString(txNew.getHash()));
    assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txNew.getEncoded()));
    txNew.sign(ECKey.fromPrivate(Hex.decode(KEY)));
    assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txNew.getEncoded()));

    assertEquals(27, txNew.getSignature().v);
    assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().r)));
    assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().s)));
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:24,代码来源:TransactionTest.java

示例8: create

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public static RemascState create(byte[] data) {
    RLPList rlpList = (RLPList)RLP.decode2(data).get(0);
    byte[] rlpRewardBalanceBytes = rlpList.get(0).getRLPData();
    byte[] rlpBurnedBalanceBytes = rlpList.get(1).getRLPData();

    BigInteger rlpRewardBalance = rlpRewardBalanceBytes == null ? BigInteger.ZERO : BigIntegers.fromUnsignedByteArray(rlpRewardBalanceBytes);
    BigInteger rlpBurnedBalance = rlpBurnedBalanceBytes == null ? BigInteger.ZERO : BigIntegers.fromUnsignedByteArray(rlpBurnedBalanceBytes);

    SortedMap<Long, List<Sibling>> rlpSiblings = RemascStorageProvider.getSiblingsFromBytes(rlpList.get(2).getRLPData());

    byte[] rlpBrokenSelectionRuleBytes = rlpList.get(3).getRLPData();

    Boolean rlpBrokenSelectionRule;

    if (rlpBrokenSelectionRuleBytes != null && rlpBrokenSelectionRuleBytes.length != 0 && rlpBrokenSelectionRuleBytes[0] != 0) {
        rlpBrokenSelectionRule = Boolean.TRUE;
    } else {
        rlpBrokenSelectionRule = Boolean.FALSE;
    }

    return new RemascState(rlpRewardBalance, rlpBurnedBalance, rlpSiblings, rlpBrokenSelectionRule);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:RemascState.java

示例9: create

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public static Sibling create(byte[] data) {
    ArrayList<RLPElement> params = RLP.decode2(data);
    RLPList sibling = (RLPList) params.get(0);

    byte[] hash = sibling.get(0).getRLPData();
    byte[] coinbase = sibling.get(1).getRLPData();
    byte[] includedBlockCoinbase = sibling.get(2).getRLPData();

    byte[] bytesPaidFees = sibling.get(3).getRLPData();
    byte[] bytesIncludedHeight = sibling.get(4).getRLPData();

    RLPElement uncleCountElement = sibling.get(5);
    byte[] bytesUncleCount = uncleCountElement != null? uncleCountElement.getRLPData():null;

    BigInteger paidFees = bytesPaidFees == null ? BigInteger.ZERO : BigIntegers.fromUnsignedByteArray(bytesPaidFees);
    long includedHeight = bytesIncludedHeight == null ? 0 : BigIntegers.fromUnsignedByteArray(bytesIncludedHeight).longValue();
    int uncleCount = bytesUncleCount == null ? 0 : BigIntegers.fromUnsignedByteArray(bytesUncleCount).intValue();

    return new Sibling(hash, coinbase, includedBlockCoinbase, paidFees, includedHeight, uncleCount);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:Sibling.java

示例10: deserializeMapOfHashesToLong

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data) {
    Map<Sha256Hash, Long> map = new HashMap<>();

    if (data == null || data.length == 0) {
        return map;
    }

    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);

    // List size must be even - key, value pairs expected in sequence
    if (rlpList.size() % 2 != 0) {
        throw new RuntimeException("deserializeMapOfHashesToLong: expected an even number of entries, but odd given");
    }

    int numEntries = rlpList.size() / 2;

    for (int k = 0; k < numEntries; k++) {
        Sha256Hash hash = Sha256Hash.wrap(rlpList.get(k * 2).getRLPData());
        Long number = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 2 + 1).getRLPData()).longValue();
        map.put(hash, number);
    }

    return map;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BridgeSerializationUtils.java

示例11: deserializeFederation

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public static Federation deserializeFederation(byte[] data, Context btcContext) {
    RLPList rlpList = (RLPList)RLP.decode2(data).get(0);

    if (rlpList.size() != FEDERATION_RLP_LIST_SIZE) {
        throw new RuntimeException(String.format("Invalid serialized Federation. Expected %d elements but got %d", FEDERATION_RLP_LIST_SIZE, rlpList.size()));
    }

    byte[] creationTimeBytes = rlpList.get(FEDERATION_CREATION_TIME_INDEX).getRLPData();
    Instant creationTime = Instant.ofEpochMilli(BigIntegers.fromUnsignedByteArray(creationTimeBytes).longValue());

    List<BtcECKey> pubKeys = ((RLPList) rlpList.get(FEDERATION_PUB_KEYS_INDEX)).stream()
            .map(pubKeyBytes -> BtcECKey.fromPublicOnly(pubKeyBytes.getRLPData()))
            .collect(Collectors.toList());

    byte[] creationBlockNumberBytes = rlpList.get(FEDERATION_CREATION_BLOCK_NUMBER_INDEX).getRLPData();
    long creationBlockNumber = BigIntegers.fromUnsignedByteArray(creationBlockNumberBytes).longValue();

    return new Federation(pubKeys, creationTime, creationBlockNumber, btcContext.getParams());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:20,代码来源:BridgeSerializationUtils.java

示例12: deserializeReleaseRequestQueue

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public static ReleaseRequestQueue deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) {
    List<ReleaseRequestQueue.Entry> entries = new ArrayList<>();

    if (data == null || data.length == 0) {
        return new ReleaseRequestQueue(entries);
    }

    RLPList rlpList = (RLPList)RLP.decode2(data).get(0);

    // Must have an even number of items
    if (rlpList.size() % 2 != 0) {
        throw new RuntimeException(String.format("Invalid serialized ReleaseRequestQueue. Expected an even number of elements, but got %d", rlpList.size()));
    }

    int n = rlpList.size() / 2;

    for (int k = 0; k < n; k++) {
        byte[] addressBytes = rlpList.get(k * 2).getRLPData();
        Address address = new Address(networkParameters, addressBytes);
        Long amount = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 2 + 1).getRLPData()).longValue();

        entries.add(new ReleaseRequestQueue.Entry(address, Coin.valueOf(amount)));
    }

    return new ReleaseRequestQueue(entries);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:BridgeSerializationUtils.java

示例13: toString

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public String toString() {
    if (!parsed) {
        rlpParse();
    }

    return "TransactionData [" + "hash=" + ByteUtil.toHexString(hash) +
            "  nonce=" + ByteUtil.toHexString(nonce) +
            ", gasPrice=" + ByteUtil.toHexString(gasPrice) +
            ", gas=" + ByteUtil.toHexString(gasLimit) +
            ", receiveAddress=" + receiveAddress.toString() +
            ", value=" + ByteUtil.toHexString(value) +
            ", data=" + ByteUtil.toHexString(data) +
            ", signatureV=" + (signature == null ? "" : signature.v) +
            ", signatureR=" + (signature == null ? "" : ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r))) +
            ", signatureS=" + (signature == null ? "" : ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s))) +
            "]";
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:Transaction.java

示例14: AccountState

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
public AccountState(byte[] rlpData) {
    this.rlpEncoded = rlpData;

    RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0);
    this.nonce = items.get(0).getRLPData() == null ? BigInteger.ZERO
            : new BigInteger(1, items.get(0).getRLPData());
    this.balance = items.get(1).getRLPData() == null ? BigInteger.ZERO
            : new BigInteger(1, items.get(1).getRLPData());
    this.stateRoot = items.get(2).getRLPData();
    this.codeHash = items.get(3).getRLPData();

    if (items.size() > 4) {
        byte[] data = items.get(4).getRLPData();

        this.stateFlags = data == null ? 0 : BigIntegers.fromUnsignedByteArray(data).intValue();
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:AccountState.java

示例15: runCreate01Resource

import org.spongycastle.util.BigIntegers; //导入依赖的package包/类
@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/create01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);

    Transaction transaction = world.getTransactionByName("tx01");

    Assert.assertNotNull(transaction);

    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash());

    Assert.assertNotNull(txinfo);
    BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());

    Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
    // According to TestRPC and geth, the gas used is 0x010c2d
    Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:DslFilesTest.java


注:本文中的org.spongycastle.util.BigIntegers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。