static void WriteParams(IAbiTypeEncoder[] encoders, ref AbiEncodeBuffer buff) { // encode transaction arguments foreach (var encoder in encoders) { encoder.Encode(ref buff); } }
public static string GetHex(params IAbiTypeEncoder[] encoders) { // get length of all encoded params int totalLen = GetEncodedLength(encoders); // create buffer to write encoded params into Span <byte> data = stackalloc byte[totalLen]; AbiEncodeBuffer buff = new AbiEncodeBuffer(data, encoders.GetTypeInfo()); // encode transaction arguments WriteParams(encoders, ref buff); // hex encode return(HexUtil.GetHexFromBytes(data, hexPrefix: true)); }
public static byte[] Encode(params IAbiTypeEncoder[] encoders) { // get length of all encoded params int totalLen = GetEncodedLength(encoders); // create buffer to write encoded params into var bytes = new byte[totalLen]; Memory <byte> data = new Memory <byte>(bytes); AbiEncodeBuffer buffer = new AbiEncodeBuffer(data, encoders.GetTypeInfo()); // encode transaction arguments WriteParams(encoders, ref buffer); return(bytes); }
public static byte[] GetFunctionCallBytes(string funcSignature, params IAbiTypeEncoder[] encoders) { // get length of all encoded params int totalLen = GetEncodedLength(encoders); // add 4 bytes for function signature totalLen += 4; // create buffer to write encoded params into byte[] bytes = new byte[totalLen]; Memory <byte> data = bytes; AbiSignature.GetMethodID(data.Span, funcSignature); AbiEncodeBuffer buffer = new AbiEncodeBuffer(data.Slice(4), encoders.GetTypeInfo()); // encode transaction arguments WriteParams(encoders, ref buffer); return(bytes); }
public void Encode(ref AbiEncodeBuffer buffer) { _encoder.Encode(ref buffer); }