本文整理汇总了Java中org.ethereum.util.ByteUtil类的典型用法代码示例。如果您正苦于以下问题:Java ByteUtil类的具体用法?Java ByteUtil怎么用?Java ByteUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteUtil类属于org.ethereum.util包,在下文中一共展示了ByteUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:BzzStoreReqMessage.java
示例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);
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:SolidityType.java
示例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);
}
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:SyncProcessor.java
示例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
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:PendingStateImpl.java
示例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);
}
}
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:DataWord.java
示例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);
}
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:EncryptionHandshake.java
示例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());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:TransactionResultDTO.java
示例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;
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:BlockBuilder.java
示例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 + "]";
}
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:NodeStatistics.java
示例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;
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:20,代码来源:BzzPeersMessage.java
示例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;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:EncryptionHandshake.java
示例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;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:EncryptionHandshake.java
示例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());
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:29,代码来源:VMTest.java
示例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));
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:CallCreate.java
示例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;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:Transaction.java
示例16: toFlatString
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
public String toFlatString() {
if (!parsed) {
parseRLP();
}
toStringBuff.setLength(0);
toStringBuff.append("BlockData [");
toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash()));
toStringBuff.append(header.toFlatString());
for (Transaction tx : getTransactionsList()) {
toStringBuff.append("\n");
toStringBuff.append(tx.toString());
}
toStringBuff.append("]");
return toStringBuff.toString();
}
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:Block.java
示例17: parse
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Override
public void parse(byte[] data) {
RLPList list = (RLPList) RLP.decode2OneItem(data, 0);
RLPList nodesRLP = (RLPList) list.get(0);
RLPItem expires = (RLPItem) list.get(1);
nodes = new ArrayList<>();
for (int i = 0; i < nodesRLP.size(); ++i) {
RLPList nodeRLP = (RLPList) nodesRLP.get(i);
Node node = new Node(nodeRLP.getRLPData());
nodes.add(node);
}
this.expires = ByteUtil.byteArrayToLong(expires.getRLPData());
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:NeighborsMessage.java
示例18: voteFeePerKbChange_nullFeeThrows
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void voteFeePerKbChange_nullFeeThrows() {
Repository repositoryMock = mock(Repository.class);
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
Transaction tx = mock(Transaction.class);
BridgeConstants constants = mock(BridgeConstants.class);
AddressBasedAuthorizer authorizer = mock(AddressBasedAuthorizer.class);
when(provider.getFeePerKbElection(any()))
.thenReturn(new ABICallElection(null));
when(tx.getSender())
.thenReturn(new RskAddress(ByteUtil.leftPadBytes(new byte[] {0x43}, 20)));
when(constants.getFeePerKbChangeAuthorizer())
.thenReturn(authorizer);
when(authorizer.isAuthorized(tx))
.thenReturn(true);
BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, repositoryMock, null, constants, provider, null, null);
bridgeSupport.voteFeePerKbChange(tx, null);
verify(provider, never()).setFeePerKb(any());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:BridgeSupportTest.java
示例19: 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
示例20: voteFeePerKbChange_successfulVote
import org.ethereum.util.ByteUtil; //导入依赖的package包/类
@Test
public void voteFeePerKbChange_successfulVote() {
Repository repositoryMock = mock(Repository.class);
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
Transaction tx = mock(Transaction.class);
BridgeConstants constants = mock(BridgeConstants.class);
AddressBasedAuthorizer authorizer = mock(AddressBasedAuthorizer.class);
byte[] senderBytes = ByteUtil.leftPadBytes(new byte[]{0x43}, 20);
when(provider.getFeePerKbElection(any()))
.thenReturn(new ABICallElection(authorizer));
when(tx.getSender())
.thenReturn(new RskAddress(senderBytes));
when(constants.getFeePerKbChangeAuthorizer())
.thenReturn(authorizer);
when(authorizer.isAuthorized(tx))
.thenReturn(true);
when(authorizer.isAuthorized(tx.getSender()))
.thenReturn(true);
when(authorizer.getRequiredAuthorizedKeys())
.thenReturn(2);
BridgeSupport bridgeSupport = new BridgeSupport(ConfigHelper.CONFIG, repositoryMock, null, constants, provider, null, null);
assertThat(bridgeSupport.voteFeePerKbChange(tx, Coin.CENT), is(1));
verify(provider, never()).setFeePerKb(any());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:BridgeSupportTest.java
注:本文中的org.ethereum.util.ByteUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论