public static byte[] formatMessageForSigning(String message) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(SIGNED_MESSAGE_HEADER_BYTES.length); bos.write(SIGNED_MESSAGE_HEADER_BYTES); byte[] messageBytes = message.getBytes(CHARSET); VarInt size = new VarInt(messageBytes.length); bos.write(size.encode()); bos.write(messageBytes); return bos.toByteArray(); } catch (IOException e) { // Cannot happen. throw new RuntimeException(e); } }
public void writeVarInt(long val) throws IOException { out.write(new VarInt(val).encode()); }
@Override public Result saveProtocolTempInfoList(long blockHeight, List<ProtocolTempInfoPo> tempInfoPoList) { return dbService.putModel(ProtocolStorageConstant.NULS_PROTOCOL_TEMP_INFO_AREA, new VarInt(blockHeight).encode(), tempInfoPoList); }
@Override public BlockProtocolInfoPo getBlockTempProtocolInfoPo(long blockHeight) { return dbService.getModel(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_AREA, new VarInt(blockHeight).encode(), BlockProtocolInfoPo.class); }
@Override public BlockProtocolInfoPo getBlockProtocolInfoPo(long blockHeight) { return dbService.getModel(ProtocolStorageConstant.BLOCK_PROTOCOL_AREA, new VarInt(blockHeight).encode(), BlockProtocolInfoPo.class); }
@Override public void deleteBlockTempProtocol(long blockHeight) { dbService.delete(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_AREA, new VarInt(blockHeight).encode()); }
@Override public Result saveProtocolInfoList(long blockHeight, List<ProtocolInfoPo> protocolInfoPoList) { return dbService.putModel(ProtocolStorageConstant.NULS_PROTOCOL_INFO_AREA, new VarInt(blockHeight).encode(), protocolInfoPoList); }
@Override public List<ProtocolInfoPo> getProtocolInfoList(long blockHeight) { return dbService.getModel(ProtocolStorageConstant.NULS_PROTOCOL_INFO_AREA, new VarInt(blockHeight).encode(), List.class); }
@Override public void removeProtocolInfoList(long blockHeight) { dbService.delete(ProtocolStorageConstant.NULS_PROTOCOL_INFO_AREA, new VarInt(blockHeight).encode()); }
@Override public List<ProtocolTempInfoPo> getProtocolTempInfoList(long blockHeight) { return dbService.getModel(ProtocolStorageConstant.NULS_PROTOCOL_TEMP_INFO_AREA, new VarInt(blockHeight).encode(), List.class); }
@Override public void removeProtocolTempInfoList(long blockHeight) { dbService.delete(ProtocolStorageConstant.NULS_PROTOCOL_TEMP_INFO_AREA, new VarInt(blockHeight).encode()); }
@Override public void deleteBlockProtocol(long blockHeight) { dbService.delete(ProtocolStorageConstant.BLOCK_PROTOCOL_AREA, new VarInt(blockHeight).encode()); }
/** * 获取固定格式的key */ private byte[] getPoKey(byte[] address, byte type, long blockHeight, int index) { return ArraysTool.concatenate(address, new byte[]{type}, SerializeUtils.uint64ToByteArray(blockHeight), new VarInt(index).encode()); } }
public byte[] getKey() { return ArraysTool.concatenate(address, new byte[]{type}, SerializeUtils.uint64ToByteArray(height), new VarInt(index).encode()); }
@Override public void clearTempBlockProtocol(long blockHeight, int version) { dbService.delete(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_INDEX, Util.intToBytes(version)); dbService.delete(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_AREA, new VarInt(blockHeight).encode()); }
@Override public void clearBlockProtocol(long blockHeight, int version) { dbService.delete(ProtocolStorageConstant.BLOCK_PROTOCOL_INDEX, Util.intToBytes(version)); dbService.delete(ProtocolStorageConstant.BLOCK_PROTOCOL_AREA, new VarInt(blockHeight).encode()); }
@Override public Result saveBlockProtocolTempInfoPo(BlockProtocolInfoPo protocolInfoPo) { List<Long> blockHeightIndex = dbService.getModel(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_INDEX, Util.intToBytes(protocolInfoPo.getVersion()), List.class); if (blockHeightIndex == null) { blockHeightIndex = new ArrayList<>(); } blockHeightIndex.add(protocolInfoPo.getBlockHeight()); dbService.putModel(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_INDEX, Util.intToBytes(protocolInfoPo.getVersion()), blockHeightIndex); return dbService.putModel(ProtocolStorageConstant.BLOCK_TEMP_PROTOCOL_AREA, new VarInt(protocolInfoPo.getBlockHeight()).encode(), protocolInfoPo); }
@Override public Result saveBlockProtocolInfoPo(BlockProtocolInfoPo protocolInfoPo) { List<Long> blockHeightIndex = dbService.getModel(ProtocolStorageConstant.BLOCK_PROTOCOL_INDEX, Util.intToBytes(protocolInfoPo.getVersion()), List.class); if (blockHeightIndex == null) { blockHeightIndex = new ArrayList<>(); } blockHeightIndex.add(protocolInfoPo.getBlockHeight()); dbService.putModel(ProtocolStorageConstant.BLOCK_PROTOCOL_INDEX, Util.intToBytes(protocolInfoPo.getVersion()), blockHeightIndex); return dbService.putModel(ProtocolStorageConstant.BLOCK_PROTOCOL_AREA, new VarInt(protocolInfoPo.getBlockHeight()).encode(), protocolInfoPo); }
public static Coin convertCoin(InputDto utxo) { Coin coin = new Coin(); byte[] txHashBytes = Hex.decode(utxo.getFromHash()); coin.setOwner(ArraysTool.concatenate(txHashBytes, new VarInt(utxo.getFromIndex()).encode())); coin.setLockTime(utxo.getLockTime()); coin.setNa(Na.valueOf(utxo.getValue())); coin.setTempOwner(AddressTool.getAddress(utxo.getAddress())); return coin; }