|
13 | 13 |
|
14 | 14 | /** |
15 | 15 | * @author Ub - H. MARTEAU |
16 | | - * @version 1.0 |
| 16 | + * @version 2.0 |
17 | 17 | */ |
18 | 18 | public class BlockCommand extends QueryBuilderBlock { |
19 | 19 |
|
| 20 | + public BlockCommand(String chainName) { |
| 21 | + setCHAIN(chainName); |
| 22 | + } |
| 23 | + |
20 | 24 | /** |
21 | 25 | * getbestblockhash |
22 | | - * |
| 26 | + * |
23 | 27 | * Returns the hash of the best (tip) block in the longest block chain. |
24 | | - * |
| 28 | + * |
25 | 29 | * Result |
26 | | - * "hex" (string) the block hash hex encoded |
27 | | - * |
| 30 | + * "hex" (string) the block hash hex encoded |
| 31 | + * |
28 | 32 | * @return the hash of the best block |
29 | 33 | * @throws MultichainException |
30 | 34 | */ |
31 | | - public static String getBestBlockHash() throws MultichainException { |
| 35 | + public String getBestBlockHash() throws MultichainException { |
32 | 36 | return executeGetBestBlockHash(); |
33 | 37 | } |
34 | 38 |
|
35 | | - |
36 | 39 | /** |
37 | 40 | * getblock "hash/height" ( verbose ) |
38 | | - * |
| 41 | + * |
39 | 42 | * If verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'. |
40 | 43 | * If verbose is true, returns an Object with information about block <hash>. |
41 | | - * |
| 44 | + * |
42 | 45 | * Arguments: |
43 | | - * 1. "hash/height" (string, required) The block hash or block height in active chain |
44 | | - * 2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data |
45 | | - * |
| 46 | + * 1. "hash/height" (string, required) The block hash or block height in active chain |
| 47 | + * 2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data |
| 48 | + * |
46 | 49 | * Result (for verbose = true): |
47 | 50 | * { |
48 | | - * "hash" : "hash", (string) the block hash (same as provided) |
49 | | - * "miner" : "miner", (string) the address of the miner |
50 | | - * "confirmations" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain |
51 | | - * "size" : n, (numeric) The block size |
52 | | - * "height" : n, (numeric) The block height or index |
53 | | - * "version" : n, (numeric) The block version |
54 | | - * "merkleroot" : "xxxx", (string) The merkle root |
55 | | - * "tx" : [ (array of string) The transaction ids |
56 | | - * "transactionid" (string) The transaction id |
57 | | - * ,... |
58 | | - * ], |
59 | | - * "time" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT) |
60 | | - * "nonce" : n, (numeric) The nonce |
61 | | - * "bits" : "1d00ffff", (string) The bits |
62 | | - * "difficulty" : x.xxx, (numeric) The difficulty |
63 | | - * "previousblockhash" : "hash", (string) The hash of the previous block |
64 | | - * "nextblockhash" : "hash" (string) The hash of the next block |
| 51 | + * "hash" : "hash", (string) the block hash (same as provided) |
| 52 | + * "miner" : "miner", (string) the address of the miner |
| 53 | + * "confirmations" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain |
| 54 | + * "size" : n, (numeric) The block size |
| 55 | + * "height" : n, (numeric) The block height or index |
| 56 | + * "version" : n, (numeric) The block version |
| 57 | + * "merkleroot" : "xxxx", (string) The merkle root |
| 58 | + * "tx" : [ (array of string) The transaction ids |
| 59 | + * "transactionid" (string) The transaction id |
| 60 | + * ,... |
| 61 | + * ], |
| 62 | + * "time" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT) |
| 63 | + * "nonce" : n, (numeric) The nonce |
| 64 | + * "bits" : "1d00ffff", (string) The bits |
| 65 | + * "difficulty" : x.xxx, (numeric) The difficulty |
| 66 | + * "previousblockhash" : "hash", (string) The hash of the previous block |
| 67 | + * "nextblockhash" : "hash" (string) The hash of the next block |
65 | 68 | * } |
66 | | - * |
| 69 | + * |
67 | 70 | * Result (for verbose=false): |
68 | | - * "data" (string) A string that is serialized, hex-encoded data for block 'hash'. |
69 | | - * |
70 | | - * |
| 71 | + * "data" (string) A string that is serialized, hex-encoded data for block 'hash'. |
| 72 | + * |
| 73 | + * |
71 | 74 | * @param hashOrHeight |
72 | 75 | * @param verbose |
73 | | - * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in the active chain |
| 76 | + * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in |
| 77 | + * the active chain |
74 | 78 | * @throws MultichainException |
75 | 79 | */ |
76 | | - public static Block getBlock(String blockHash, boolean verbose) throws MultichainException { |
| 80 | + public Block getBlock(String blockHash, boolean verbose) throws MultichainException { |
77 | 81 | String stringBlock = executeGetBlock(blockHash, verbose); |
78 | 82 |
|
79 | 83 | return BlockFormatter.formatBlock(stringBlock); |
80 | 84 | } |
81 | 85 |
|
82 | 86 | /** |
83 | 87 | * {@link #getBlock(String, boolean)} without verbose |
| 88 | + * |
84 | 89 | * @param blockHash |
85 | | - * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in the active chain |
| 90 | + * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in |
| 91 | + * the active chain |
86 | 92 | * @throws MultichainException |
87 | 93 | */ |
88 | | - public static Block getBlock(String blockHash) throws MultichainException { |
| 94 | + public Block getBlock(String blockHash) throws MultichainException { |
89 | 95 | String stringBlock = executeGetBlock(blockHash, true); |
90 | 96 |
|
91 | 97 | return BlockFormatter.formatBlock(stringBlock); |
92 | 98 | } |
93 | 99 |
|
94 | 100 | /** |
95 | 101 | * {@link #getBlock(String, boolean)} with long value of Height |
| 102 | + * |
96 | 103 | * @param blockHash |
97 | 104 | * @param verbose |
98 | | - * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in the active chain |
| 105 | + * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in |
| 106 | + * the active chain |
99 | 107 | * @throws MultichainException |
100 | 108 | */ |
101 | | - public static Block getBlock(long blockHeight, boolean verbose) throws MultichainException { |
| 109 | + public Block getBlock(long blockHeight, boolean verbose) throws MultichainException { |
102 | 110 | String blockHash = Long.toString(blockHeight); |
103 | 111 |
|
104 | 112 | return getBlock(blockHash, verbose); |
105 | 113 | } |
106 | 114 |
|
107 | 115 | /** |
108 | 116 | * {@link #getBlock(long, boolean)} without verbose |
| 117 | + * |
109 | 118 | * @param blockHash |
110 | | - * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in the active chain |
| 119 | + * @return Block : information about the block with hash (retrievable from getblockhash) or at the given height in |
| 120 | + * the active chain |
111 | 121 | * @throws MultichainException |
112 | 122 | */ |
113 | | - public static Block getBlock(long blockHeight) throws MultichainException { |
| 123 | + public Block getBlock(long blockHeight) throws MultichainException { |
114 | 124 | String blockHash = Long.toString(blockHeight); |
115 | 125 |
|
116 | 126 | return getBlock(blockHash, true); |
117 | 127 | } |
118 | 128 |
|
119 | 129 | /** |
120 | 130 | * getblockcount |
121 | | - * |
| 131 | + * |
122 | 132 | * Returns the number of blocks in the longest block chain. |
123 | | - * |
| 133 | + * |
124 | 134 | * Result: |
125 | | - * n (numeric) The current block count |
126 | | - * |
| 135 | + * n (numeric) The current block count |
| 136 | + * |
127 | 137 | * @return The Actual count of blocks in the BlockChain. |
128 | 138 | * @throws MultichainException |
129 | 139 | */ |
130 | | - public static long getBlockCount() throws MultichainException { |
| 140 | + public long getBlockCount() throws MultichainException { |
131 | 141 | String stringBlockCount = executeGetBlockCount(); |
132 | 142 |
|
133 | 143 | return BlockFormatter.formatBlockCount(stringBlockCount); |
134 | 144 | } |
135 | 145 |
|
136 | 146 | /** |
137 | 147 | * getblockhash index |
138 | | - * |
| 148 | + * |
139 | 149 | * Returns hash of block in best-block-chain at index provided. |
140 | | - * |
| 150 | + * |
141 | 151 | * Arguments: |
142 | | - * 1. index (numeric, required) The block index |
143 | | - * |
| 152 | + * 1. index (numeric, required) The block index |
| 153 | + * |
144 | 154 | * Result: |
145 | | - * "hash" (string) The block hash |
146 | | - * |
| 155 | + * "hash" (string) The block hash |
| 156 | + * |
147 | 157 | * @return the hash of the best block |
148 | 158 | * @throws MultichainException |
149 | 159 | */ |
150 | | - public static String getBlockHash(long index) throws MultichainException { |
| 160 | + public String getBlockHash(long index) throws MultichainException { |
151 | 161 | return executeGetBlockHash(index); |
152 | 162 | } |
153 | 163 |
|
|
0 commit comments