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


Java ByteUtil.bigIntegerToBytes方法代码示例

本文整理汇总了Java中org.ethereum.util.ByteUtil.bigIntegerToBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ByteUtil.bigIntegerToBytes方法的具体用法?Java ByteUtil.bigIntegerToBytes怎么用?Java ByteUtil.bigIntegerToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ethereum.util.ByteUtil的用法示例。


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

示例1: sendStatus

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
/*************************
 *    Message Sending    *
 *************************/

@Override
public void sendStatus() {
    byte protocolVersion = version.getCode();
    int networkId = config.networkId();

    BlockChainStatus blockChainStatus = this.blockchain.getStatus();
    Block bestBlock = blockChainStatus.getBestBlock();
    BigInteger totalDifficulty = blockChainStatus.getTotalDifficulty();

    // Original status
    Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true);
    org.ethereum.net.eth.message.StatusMessage msg = new org.ethereum.net.eth.message.StatusMessage(protocolVersion, networkId,
            ByteUtil.bigIntegerToBytes(totalDifficulty), bestBlock.getHash(), genesis.getHash());
    sendMessage(msg);

    // RSK new protocol send status
    Status status = new Status(bestBlock.getNumber(), bestBlock.getHash(), bestBlock.getParentHash(), totalDifficulty);
    RskMessage rskmessage = new RskMessage(config, new StatusMessage(status));
    loggerNet.trace("Sending status best block {} to {}", status.getBestBlockNumber(), this.messageSender.getPeerNodeID().toString());
    sendMessage(rskmessage);

    ethState = EthState.STATUS_SENT;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:28,代码来源:RskWireProtocol.java

示例2: createFakePendingBlock

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
private Block createFakePendingBlock(Block best) {
    Trie txsTrie = new TrieImpl();

    // creating fake lightweight calculated block with no hashes calculations
    return new Block(best.getHash(),
                        emptyUncleHashList, // uncleHash
                        new byte[32], //coinbase
                        new byte[32], // log bloom - from tx receipts
                        best.getDifficulty(), // difficulty
                        best.getNumber() + 1, //number
                        ByteUtil.longToBytesNoLeadZeroes(Long.MAX_VALUE), // max Gas Limit
                        0,  // gas used
                        best.getTimestamp() + 1,  // block time
                        new byte[0],  // extra data
                        new byte[0],  // mixHash (to mine)
                        new byte[0],  // nonce   (to mine)
                        new byte[0],
                        new byte[0],
                        new byte[0],
                        new byte[32],  // receiptsRoot
                        txsTrie.getHash(),  // TransactionsRoot-
                        new byte[32],  // stateRoot
                        Collections.<Transaction>emptyList(), // tx list
                        Collections.<BlockHeader>emptyList(), // uncle list
                        ByteUtil.bigIntegerToBytes(BigInteger.ZERO)); //minimum gas price
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:PendingStateImpl.java

示例3: createTransaction

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
@Override
public Transaction createTransaction(BigInteger nonce,
                                     BigInteger gasPrice,
                                     BigInteger gas,
                                     byte[] receiveAddress,
                                     BigInteger value, byte[] data) {

    byte[] nonceBytes = ByteUtil.bigIntegerToBytes(nonce);
    byte[] gasPriceBytes = ByteUtil.bigIntegerToBytes(gasPrice);
    byte[] gasBytes = ByteUtil.bigIntegerToBytes(gas);
    byte[] valueBytes = ByteUtil.bigIntegerToBytes(value);
    byte chainId = config.getBlockchainConfig().getCommonConstants().getChainId();

    return new Transaction(nonceBytes, gasPriceBytes, gasBytes,
            receiveAddress, valueBytes, data, chainId);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:EthereumImpl.java

示例4: makeAuthInitiateV4

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
AuthResponseMessageV4 makeAuthInitiateV4(AuthInitiateMessageV4 initiate, ECKey key) {
    initiatorNonce = initiate.nonce;
    remotePublicKey = initiate.publicKey;
    BigInteger secretScalar = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger();
    byte[] token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);
    byte[] signed = xor(token, initiatorNonce);

    ECKey ephemeral = ECKey.recoverFromSignature(recIdFromSignatureV(initiate.signature.v),
            initiate.signature, signed, false);
    if (ephemeral == null) {
        throw new RuntimeException("failed to recover signatue from message");
    }
    remoteEphemeralKey = ephemeral.getPubKeyPoint();
    AuthResponseMessageV4 response = new AuthResponseMessageV4();
    response.ephemeralPublicKey = ephemeralKey.getPubKeyPoint();
    response.nonce = responderNonce;
    return response;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:EncryptionHandshake.java

示例5: CallCreate

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public CallCreate(JSONObject callCreateJSON) {

        String data = callCreateJSON.get("data").toString();
        String destination = callCreateJSON.get("destination").toString();
        String gasLimit = callCreateJSON.get("gasLimit").toString();
        String value = callCreateJSON.get("value").toString();

        if (data != null && data.length() > 2)
            this.data = Utils.parseData(data);
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.destination = Utils.parseData(destination);
        this.gasLimit = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasLimit));
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:CallCreate.java

示例6: makeAuthInitiate

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
AuthResponseMessage makeAuthInitiate(AuthInitiateMessage initiate, ECKey key) {
    initiatorNonce = initiate.nonce;
    remotePublicKey = initiate.publicKey;
    BigInteger secretScalar = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger();
    byte[] token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);
    byte[] signed = xor(token, initiatorNonce);

    ECKey ephemeral = ECKey.recoverFromSignature(recIdFromSignatureV(initiate.signature.v),
            initiate.signature, signed, false);
    if (ephemeral == null) {
        throw new RuntimeException("failed to recover signatue from message");
    }
    remoteEphemeralKey = ephemeral.getPubKeyPoint();
    AuthResponseMessage response = new AuthResponseMessage();
    response.isTokenUsed = initiate.isTokenUsed;
    response.ephemeralPublicKey = ephemeralKey.getPubKeyPoint();
    response.nonce = responderNonce;
    return response;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:20,代码来源:EncryptionHandshake.java

示例7: CallCreate

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public CallCreate(JSONObject callCreateJSON) {

        String data = callCreateJSON.get("data").toString();
        String destination = callCreateJSON.get("destination").toString();
        String gasLimit = callCreateJSON.get("gasLimit").toString();
        String value = callCreateJSON.get("value").toString();

        if (data != null && data.length() > 2)
            this.data = Hex.decode(data.substring(2));
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.destination = Hex.decode(destination);
        this.gasLimit = TestCase.toBigInt(gasLimit).longValueExact();
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:CallCreate.java

示例8: sendTxAndWait

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
private TransactionReceipt sendTxAndWait(byte[] receiveAddress, byte[] data) throws InterruptedException {

        byte[] senderPrivateKey = Hex.decode("");
        byte[] fromAddress = ECKey.fromPrivate(senderPrivateKey).getAddress();
        BigInteger nonce = ethereum.getRepository().getNonce(fromAddress);
        Transaction tx = new Transaction(
                ByteUtil.bigIntegerToBytes(nonce),
                ByteUtil.longToBytesNoLeadZeroes(ethereum.getGasPrice()),
                ByteUtil.longToBytesNoLeadZeroes(200000),
                receiveAddress,
                ByteUtil.bigIntegerToBytes(BigInteger.valueOf(1)),  // 1_000_000_000 gwei, 1_000_000_000_000L szabo, 1_000_000_000_000_000L finney, 1_000_000_000_000_000_000L ether
                data,
                ethereum.getChainIdForNextBlock());

        tx.sign(ECKey.fromPrivate(senderPrivateKey));
        logger.info("<=== Sending transaction: " + tx);
        ethereum.submitTransaction(tx);

        return waitForTx(tx.getHash());
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:SendTransaction.java

示例9: makeAuthInitiateV4

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
AuthResponseMessageV4 makeAuthInitiateV4(AuthInitiateMessageV4 initiate, ECKey key) {
    initiatorNonce = initiate.nonce;
    remotePublicKey = initiate.publicKey;

    BigInteger secretScalar = key.keyAgreement(remotePublicKey);

    byte[] token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);
    byte[] signed = xor(token, initiatorNonce);

    ECKey ephemeral = ECKey.recoverFromSignature(recIdFromSignatureV(initiate.signature.v),
            initiate.signature, signed);
    if (ephemeral == null) {
        throw new RuntimeException("failed to recover signatue from message");
    }
    remoteEphemeralKey = ephemeral.getPubKeyPoint();
    AuthResponseMessageV4 response = new AuthResponseMessageV4();
    response.ephemeralPublicKey = ephemeralKey.getPubKeyPoint();
    response.nonce = responderNonce;
    return response;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:EncryptionHandshake.java

示例10: createAuthInitiate

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
/**
 * Create a handshake auth message
 *
 * @param token previous token if we had a previous session
 * @param key our private key
 */
public AuthInitiateMessage createAuthInitiate(@Nullable byte[] token, ECKey key) {
    AuthInitiateMessage message = new AuthInitiateMessage();
    boolean isToken;
    if (token == null) {
        isToken = false;
        BigInteger secretScalar = key.keyAgreement(remotePublicKey);
        token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);
    } else {
        isToken = true;
    }

    byte[] nonce = initiatorNonce;
    byte[] signed = xor(token, nonce);
    message.signature = ephemeralKey.sign(signed);
    message.isTokenUsed = isToken;
    message.ephemeralPublicHash = sha3(ephemeralKey.getPubKey(), 1, 64);
    message.publicKey = key.getPubKeyPoint();
    message.nonce = initiatorNonce;
    return message;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:27,代码来源:EncryptionHandshake.java

示例11: createAuthInitiateV4

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
/**
 * Create a handshake auth message defined by EIP-8
 *
 * @param key our private key
 */
public AuthInitiateMessageV4 createAuthInitiateV4(ECKey key) {
    AuthInitiateMessageV4 message = new AuthInitiateMessageV4();
    BigInteger secretScalar = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger();
    byte[] token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);

    byte[] nonce = initiatorNonce;
    byte[] signed = xor(token, nonce);
    message.signature = ephemeralKey.sign(signed);
    message.publicKey = key.getPubKeyPoint();
    message.nonce = initiatorNonce;
    return message;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:EncryptionHandshake.java

示例12: agreeSecret

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
void agreeSecret(byte[] initiatePacket, byte[] responsePacket) {
    BigInteger secretScalar = remoteEphemeralKey.multiply(ephemeralKey.getPrivKey()).normalize().getXCoord().toBigInteger();
    byte[] agreedSecret = ByteUtil.bigIntegerToBytes(secretScalar, SECRET_SIZE);
    byte[] sharedSecret = sha3(agreedSecret, sha3(responderNonce, initiatorNonce));
    byte[] aesSecret = sha3(agreedSecret, sharedSecret);
    secrets = new Secrets();
    secrets.aes = aesSecret;
    secrets.mac = sha3(agreedSecret, aesSecret);
    secrets.token = sha3(sharedSecret);

    SHA3Digest mac1 = new SHA3Digest(MAC_SIZE);
    mac1.update(xor(secrets.mac, responderNonce), 0, secrets.mac.length);
    byte[] buf = new byte[32];
    new SHA3Digest(mac1).doFinal(buf, 0);
    mac1.update(initiatePacket, 0, initiatePacket.length);
    new SHA3Digest(mac1).doFinal(buf, 0);
    SHA3Digest mac2 = new SHA3Digest(MAC_SIZE);
    mac2.update(xor(secrets.mac, initiatorNonce), 0, secrets.mac.length);
    new SHA3Digest(mac2).doFinal(buf, 0);
    mac2.update(responsePacket, 0, responsePacket.length);
    new SHA3Digest(mac2).doFinal(buf, 0);
    if (isInitiator) {
        secrets.egressMac = mac1;
        secrets.ingressMac = mac2;
    } else {
        secrets.egressMac = mac2;
        secrets.ingressMac = mac1;
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:EncryptionHandshake.java

示例13: Exec

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public Exec(JSONObject exec) {

        String address = exec.get("address").toString();
        String caller = exec.get("caller").toString();

        String code = exec.get("code").toString();
        String data = exec.get("data").toString();

        String gas = exec.get("gas").toString();
        String gasPrice = exec.get("gasPrice").toString();
        String origin = exec.get("origin").toString();

        String value = exec.get("value").toString();

        this.address = Hex.decode(address);
        this.caller = Hex.decode(caller);

        if (code != null && code.length() > 2)
            this.code = Hex.decode(code.substring(2));
        else
            this.code = ByteUtil.EMPTY_BYTE_ARRAY;

        if (data != null && data.length() > 2)
            this.data = Hex.decode(data.substring(2));
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.gas = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gas));
        this.gasPrice = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasPrice));

        this.origin = Hex.decode(origin);
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:34,代码来源:Exec.java

示例14: createTransaction

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public Transaction createTransaction(ECKey sender, long nonce, byte[] toAddress, BigInteger value, byte[] data) {
    Transaction transaction = new Transaction(ByteUtil.longToBytesNoLeadZeroes(nonce),
            ByteUtil.longToBytesNoLeadZeroes(gasPrice),
            ByteUtil.longToBytesNoLeadZeroes(gasLimit),
            toAddress, ByteUtil.bigIntegerToBytes(value),
            data,
            null);
    transaction.sign(sender);
    return transaction;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:11,代码来源:StandaloneBlockchain.java

示例15: Exec

import org.ethereum.util.ByteUtil; //导入方法依赖的package包/类
public Exec(JSONObject exec) {

        String address = exec.get("address").toString();
        String caller = exec.get("caller").toString();

        String code = exec.get("code").toString();
        String data = exec.get("data").toString();

        String gas = exec.get("gas").toString();
        String gasPrice = exec.get("gasPrice").toString();
        String origin = exec.get("origin").toString();

        String value = exec.get("value").toString();

        this.address = Utils.parseData(address);
        this.caller = Utils.parseData(caller);

        if (code != null && code.length() > 2)
            this.code = Utils.parseData(code);
        else
            this.code = ByteUtil.EMPTY_BYTE_ARRAY;

        if (data != null && data.length() > 2)
            this.data = Utils.parseData(data);
        else
            this.data = ByteUtil.EMPTY_BYTE_ARRAY;

        this.gas = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gas));
        this.gasPrice = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasPrice));

        this.origin = Utils.parseData(origin);
        this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value));
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:34,代码来源:Exec.java


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