Updated ABI Number coder for BigNumber API change.

This commit is contained in:
Richard Moore 2020-04-15 16:49:55 -04:00
parent 7dcefcbf71
commit 284771ea39
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -21,17 +21,17 @@ export class NumberCoder extends Coder {
let v = BigNumber.from(value);
// Check bounds are safe for encoding
let maxUintValue = MaxUint256.maskn(writer.wordSize * 8);
let maxUintValue = MaxUint256.mask(writer.wordSize * 8);
if (this.signed) {
let bounds = maxUintValue.maskn(this.size * 8 - 1);
let bounds = maxUintValue.mask(this.size * 8 - 1);
if (v.gt(bounds) || v.lt(bounds.add(One).mul(NegativeOne))) {
this._throwError("value out-of-bounds", value);
}
} else if (v.lt(Zero) || v.gt(maxUintValue.maskn(this.size * 8))) {
} else if (v.lt(Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
this._throwError("value out-of-bounds", value);
}
v = v.toTwos(this.size * 8).maskn(this.size * 8);
v = v.toTwos(this.size * 8).mask(this.size * 8);
if (this.signed) {
v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
@ -41,7 +41,7 @@ export class NumberCoder extends Coder {
}
decode(reader: Reader): any {
let value = reader.readValue().maskn(this.size * 8);
let value = reader.readValue().mask(this.size * 8);
if (this.signed) {
value = value.fromTwos(this.size * 8);