public static RawTransaction Decode(string hexRawTransaction) { if (!StringUtils.IsHex(hexRawTransaction)) { return(null); } var rawTxBytes = ByteUtils.ToByteArray(hexRawTransaction); var list = RlpDecoder.Decode(rawTxBytes); if (list == null) { return(null); } var rlpContent = list.Values; //It should only has one element. if (rlpContent.Count != 1) { return(null); } var rawTransaction = new RawTransaction(); var listValues = ((RlpList)rlpContent[0]).Values; for (int index = 0; index < listValues.Count; index++) { FillTransaction(rawTransaction, listValues, index); } return(rawTransaction); }
public static BigDecimal Amount(string hexString, int precision, int scale) { var balBytes = ByteUtils.ToByteArray(hexString); if (balBytes == null) { return(null); } var balInteger = ByteUtils.BytesToBigInt(balBytes); return(ByteUtils.BigIntToBigDecimal(balInteger, precision, scale)); }
public static string BuildSignature(byte[] cert, byte[] txRawHash, string privateKey) { var txRawBytes = CryptoUtils.Blake2b(txRawHash); var cerHexBytes = CryptoUtils.Sha256(cert); var message = new byte[txRawBytes.Length + cerHexBytes.Length]; Array.Copy(cerHexBytes, 0, message, 0, cerHexBytes.Length); Array.Copy(txRawBytes, 0, message, cerHexBytes.Length, txRawBytes.Length); var key = ECKeyPair.Create(ByteUtils.ToByteArray(privateKey)); var signature = ECDSASign.SignMessage(CryptoUtils.Sha256(message), key, false); var signBytes = signature.ToByteArray(); _logger.Info("signature: {} {}", ByteUtils.ToHexString(signBytes, null), ByteUtils.CleanHexPrefix(ByteUtils.ToHexString(signature.R, Prefix.ZeroLowerX)) + ByteUtils.CleanHexPrefix(ByteUtils.ToHexString(signature.S, Prefix.ZeroLowerX)) + "0" + signature.V); return(ByteUtils.ToHexString(signBytes, null)); }
private static string EncodeAddress(string address) { if (!StringUtils.IsHex(address)) { throw new InvalidArgumentException("Parameter format is not hex string"); } var paramBytes = ByteUtils.ToByteArray(address); if (paramBytes == null || paramBytes.Length > MAX_BYTE_LENGTH) { throw new InvalidArgumentException("Parameter format is hex string size too large, or null"); } if (paramBytes.Length < MAX_BYTE_LENGTH) { var fillingZero = new byte[MAX_BYTE_LENGTH]; Array.Copy(paramBytes, 0, fillingZero, MAX_BYTE_LENGTH - paramBytes.Length, paramBytes.Length); return(ByteUtils.ToHexString(fillingZero, null)); } else { return(ByteUtils.CleanHexPrefix(address)); } }