Coverage Summary for Class: BlockIdentifier (org.ethereum.core)
Class |
Class, %
|
Method, %
|
Line, %
|
BlockIdentifier |
0%
(0/1)
|
0%
(0/6)
|
0%
(0/15)
|
1 package org.ethereum.core;
2 /*
3 * This file is part of RskJ
4 * Copyright (C) 2017 RSK Labs Ltd.
5 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 import org.ethereum.util.ByteUtil;
22 import org.ethereum.util.RLP;
23 import org.ethereum.util.RLPList;
24
25 import java.math.BigInteger;
26
27 import static org.ethereum.util.ByteUtil.byteArrayToLong;
28
29 /**
30 * Block identifier holds block hash and number <br>
31 * This tuple is used in some places of the core,
32 * like by {@link org.ethereum.net.eth.message.EthMessageCodes#NEW_BLOCK_HASHES} message wrapper
33 *
34 * @author Mikhail Kalinin
35 * @since 04.09.2015
36 */
37 public class BlockIdentifier {
38
39 /**
40 * Block hash
41 */
42 private byte[] hash;
43
44 /**
45 * Block number
46 */
47 private long number;
48
49 public BlockIdentifier(RLPList rlp) {
50 this.hash = rlp.get(0).getRLPData();
51 this.number = byteArrayToLong(rlp.get(1).getRLPData());
52 }
53
54 public BlockIdentifier(byte[] hash, long number) {
55 this.hash = hash;
56 this.number = number;
57 }
58
59 public byte[] getHash() {
60 return hash;
61 }
62
63 public long getNumber() {
64 return number;
65 }
66
67 public byte[] getEncoded() {
68 byte[] hash = RLP.encodeElement(this.hash);
69 byte[] number = RLP.encodeBigInteger(BigInteger.valueOf(this.number));
70
71 return RLP.encodeList(hash, number);
72 }
73
74 @Override
75 public String toString() {
76 return "BlockIdentifier {" +
77 "hash=" + ByteUtil.toHexString(hash) +
78 ", number=" + number +
79 '}';
80 }
81 }