Skip to content

Commit

Permalink
Merge pull request #1022 from kantagara/nikola/abi-biginteger-array-s…
Browse files Browse the repository at this point in the history
…upport

Making sure abi encoding doesn't strip out some values but rather throws an exception.. Also added support for BigInteger Array ABI Encodings.
  • Loading branch information
juanfranblanco committed Apr 11, 2024
2 parents 942684d + fd8bc0e commit 07c75b2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Nethereum.ABI/ABIEncode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Nethereum.ABI.Decoders;
Expand Down Expand Up @@ -115,9 +116,7 @@ private List<ABIValue> ConvertValuesToDefaultABIValues(params object[] values)
abiValues.Add(new ABIValue(new IntType("int256"), bigIntValue));
}
}


if (value.IsNumber())
else if (value.IsNumber())
{
var bigInt = BigInteger.Parse(value.ToString());
if (bigInt >= 0)
Expand All @@ -129,23 +128,28 @@ private List<ABIValue> ConvertValuesToDefaultABIValues(params object[] values)
abiValues.Add(new ABIValue(new IntType("int256"), value));
}
}

if (value is string)
else if (value is string)
{
abiValues.Add(new ABIValue(new StringType(), value));
}

if (value is bool)
else if (value is bool)
{
abiValues.Add(new ABIValue(new BoolType(), value));
}

if (value is byte[])
else if (value is byte[])
{
abiValues.Add(new ABIValue(new BytesType(), value));
}
else if (value is BigInteger[])
{
abiValues.Add(new ABIValue(new DynamicArrayType("uint[]"), value));
}
else
{
throw new InvalidDataException($"Unexpected data type: {value.GetType()}");
}
}

return abiValues;
}

Expand Down

0 comments on commit 07c75b2

Please sign in to comment.