本文整理汇总了Java中org.ethereum.util.ByteUtil类的典型用法代码示例。如果您正苦于以下问题:Java ByteUtil类的具体用法?Java ByteUtil怎么用?Java ByteUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteUtil类属于org.ethereum.util包,在下文中一共展示了ByteUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
protected void decode() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
key = new Key(paramsList.get(0).getRLPData());
data = paramsList.get(1).getRLPData();
if (paramsList.size() > 2) {
id = ByteUtil.byteArrayToLong(paramsList.get(2).getRLPData());
}
if (paramsList.size() > 3) {
metadata = paramsList.get(2).getRLPData();
}
parsed = true;
}
示例2: encodeList
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
public byte[] encodeList(List l) {
byte[][] elems;
if (elementType.isDynamicType()) {
elems = new byte[l.size() * 2 + 1][];
elems[0] = IntType.encodeInt(l.size());
int offset = l.size() * 32;
for (int i = 0; i < l.size(); i++) {
elems[i + 1] = IntType.encodeInt(offset);
byte[] encoded = elementType.encode(l.get(i));
elems[l.size() + i + 1] = encoded;
offset += 32 * ((encoded.length - 1) / 32 + 1);
}
} else {
elems = new byte[l.size() + 1][];
elems[0] = IntType.encodeInt(l.size());
for (int i = 0; i < l.size(); i++) {
elems[i + 1] = elementType.encode(l.get(i));
}
}
return ByteUtil.merge(elems);
}
示例3: blockHeaderIsValid
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
public boolean blockHeaderIsValid(@Nonnull BlockHeader header, @Nonnull BlockHeader parentHeader) {
if (!ByteUtil.fastEquals(parentHeader.getHash(), header.getParentHash())) {
return false;
}
if (header.getNumber() != parentHeader.getNumber() + 1) {
return false;
}
if (!blockHeaderIsValid(header)) {
return false;
}
return blockParentValidationRule.validate(header, parentHeader);
}
示例4: 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
}
示例5: assign
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public void assign(byte[] data) {
if (data == null) {
this.data = ByteUtil.EMPTY_BYTE_ARRAY;
} else if (data.length == 32) {
this.data = data;
}
else if (data.length <= 32) {
if (this.data==null) {
newZeroData();
} else {
zero(); // first clear
}
System.arraycopy(data, 0, this.data, 32 - data.length, data.length);
}else {
throw new RuntimeException("Data word can't exceed 32 bytes: " + data);
}
}
示例6: decryptAuthResponseV4
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public AuthResponseMessageV4 decryptAuthResponseV4(byte[] in, ECKey myKey) {
try {
byte[] prefix = new byte[2];
System.arraycopy(in, 0, prefix, 0, 2);
short size = ByteUtil.bigEndianToShort(prefix, 0);
byte[] ciphertext = new byte[size];
System.arraycopy(in, 2, ciphertext, 0, size);
byte[] plaintext = ECIESCoder.decrypt(myKey.getPrivKey(), ciphertext, prefix);
return AuthResponseMessageV4.decode(plaintext);
} catch (IOException | InvalidCipherTextException e) {
throw Throwables.propagate(e);
}
}
示例7: TransactionResultDTO
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public TransactionResultDTO (Block b, Integer index, Transaction tx) {
hash = TypeConverter.toJsonHex(tx.getHash());
if (Arrays.equals(tx.getNonce(), ByteUtil.EMPTY_BYTE_ARRAY)) {
nonce = "0";
} else {
nonce = TypeConverter.toJsonHex(tx.getNonce());
}
blockHash = b != null ? TypeConverter.toJsonHex(b.getHash()) : null;
blockNumber = b != null ? TypeConverter.toJsonHex(b.getNumber()) : null;
transactionIndex = index != null ? TypeConverter.toJsonHex(index) : null;
from= TypeConverter.toJsonHex(tx.getSender().getBytes());
to = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
gas = TypeConverter.toJsonHex(tx.getGasLimit()); // Todo: unclear if it's the gas limit or gas consumed what is asked
gasPrice = TypeConverter.toJsonHex(tx.getGasPrice());
if (Arrays.equals(tx.getValue(), ByteUtil.EMPTY_BYTE_ARRAY)) {
value = "0";
} else {
value = TypeConverter.toJsonHex(tx.getValue());
}
input = TypeConverter.toJsonHex(tx.getData());
}
示例8: build
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public static Block build(Env env){
Block block = new Block(
ByteUtil.EMPTY_BYTE_ARRAY,
ByteUtil.EMPTY_BYTE_ARRAY,
env.getCurrentCoinbase(),
ByteUtil.EMPTY_BYTE_ARRAY,
env.getCurrentDifficulty(),
byteArrayToLong(env.getCurrentNumber()),
env.getCurrentGasLimit(),
0L,
byteArrayToLong(env.getCurrentTimestamp()),
new byte[32],
ByteUtil.ZERO_BYTE_ARRAY,
ByteUtil.ZERO_BYTE_ARRAY,
null, null);
return block;
}
示例9: toString
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
public String toString() {
return "NodeStat[reput: " + getReputation() + "(" + savedReputation + "), discover: " +
discoverInPong + "/" + discoverOutPing + " " +
discoverOutPong + "/" + discoverInPing + " " +
discoverInNeighbours + "/" + discoverOutFind + " " +
discoverOutNeighbours + "/" + discoverInFind + " " +
", rlpx: " + rlpxHandshake + "/" + rlpxAuthMessagesSent + "/" + rlpxConnectionAttempts + " " +
rlpxInMessages + "/" + rlpxOutMessages +
", eth: " + ethHandshake + "/" + ethInbound + "/" + ethOutbound + " " +
(ethLastInboundStatusMsg != null ? ByteUtil.toHexString(ethLastInboundStatusMsg.getTotalDifficulty()) : "-") + " " +
(disconnected ? "X " : "") +
(rlpxLastLocalDisconnectReason != null ? ("<=" + rlpxLastLocalDisconnectReason) : " ") +
(rlpxLastRemoteDisconnectReason != null ? ("=>" + rlpxLastRemoteDisconnectReason) : " ") +
"[" + clientId + "]";
}
示例10: decode
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
protected void decode() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
peers = new ArrayList<>();
RLPList addrs = (RLPList) paramsList.get(0);
for (RLPElement a : addrs) {
peers.add(PeerAddress.parse((RLPList) a));
}
timeout = ByteUtil.byteArrayToLong(paramsList.get(1).getRLPData());;
if (paramsList.size() > 2) {
key = new Key(paramsList.get(2).getRLPData());
}
if (paramsList.size() > 3) {
id = ByteUtil.byteArrayToLong(paramsList.get(3).getRLPData());;
}
parsed = true;
}
示例11: 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;
}
示例12: 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 = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger();
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.getPubKeyPoint().getEncoded(false), 1, 64);
message.publicKey = key.getPubKeyPoint();
message.nonce = initiatorNonce;
return message;
}
示例13: testDUPN_1
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
/**
* Generic test function for DUP1-16
*
* @param n in DUPn
*/
private void testDUPN_1(int n) {
VM vm = new VM();
byte operation = (byte) (OpCode.DUP1.val() + n - 1);
String programCode = "";
for (int i = 0; i < n; i++) {
programCode += "60" + (12 + i);
}
program = new Program(ByteUtil.appendByte(Hex.decode(programCode.getBytes()), operation), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000012";
int expectedLen = n + 1;
for (int i = 0; i < expectedLen; i++) {
vm.step(program);
}
assertEquals(expectedLen, program.getStack().toArray().length);
assertEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase());
for (int i = 0; i < expectedLen - 2; i++) {
assertNotEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase());
}
assertEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase());
}
示例14: 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));
}
示例15: Transaction
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data,
byte chainId) {
this.nonce = ByteUtil.cloneBytes(nonce);
this.gasPrice = ByteUtil.cloneBytes(gasPrice);
this.gasLimit = ByteUtil.cloneBytes(gasLimit);
this.receiveAddress = parseRskAddress(ByteUtil.cloneBytes(receiveAddress));
if (value == null || ByteUtil.isSingleZero(value)) {
this.value = EMPTY_BYTE_ARRAY;
} else {
this.value = ByteUtil.cloneBytes(value);
}
this.data = ByteUtil.cloneBytes(data);
this.chainId = chainId;
parsed = true;
}