-
Notifications
You must be signed in to change notification settings - Fork 77
Update AssemblyScript to 0.19.10 #185
Changes from all commits
ada645c
8d4bde7
8987ec2
5ff910e
54f8a09
12f2cc5
10fa0b1
6ba262f
f0c919f
1c9f8d2
2114950
17dd90f
22b4982
7f0994d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "10" | ||
- "12" | ||
- "14" | ||
- "16" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { Address, BigInt, Bytes, Wrapped } from '..' | ||
import '../common/eager_offset' | ||
import { Bytes, Wrapped } from '../common/collections' | ||
import { Address, BigInt } from '../common/numbers' | ||
|
||
/** Host Ethereum interface */ | ||
export declare namespace ethereum { | ||
|
@@ -33,8 +35,22 @@ export namespace ethereum { | |
* A dynamically typed value used when accessing Ethereum data. | ||
*/ | ||
export class Value { | ||
kind: ValueKind | ||
data: ValuePayload | ||
constructor( | ||
public kind: ValueKind, | ||
public data: ValuePayload, | ||
) {} | ||
|
||
@operator('<') | ||
lt(other: Value): boolean { | ||
abort("Less than operator isn't supported in Value") | ||
return false | ||
} | ||
|
||
@operator('>') | ||
gt(other: Value): boolean { | ||
abort("Greater than operator isn't supported in Value") | ||
return false | ||
} | ||
|
||
toAddress(): Address { | ||
assert(this.kind == ValueKind.ADDRESS, 'Ethereum value is not an address') | ||
|
@@ -97,7 +113,7 @@ export namespace ethereum { | |
let valueArray = this.toArray() | ||
let out = new Array<T>(valueArray.length) | ||
for (let i: i32 = 0; i < valueArray.length; i++) { | ||
out[i] = valueArray[i].toTuple() as T | ||
out[i] = <T>valueArray[i].toTuple() | ||
} | ||
return out | ||
} | ||
|
@@ -182,81 +198,47 @@ export namespace ethereum { | |
|
||
static fromAddress(address: Address): Value { | ||
assert(address.length == 20, 'Address must contain exactly 20 bytes') | ||
|
||
let token = new Value() | ||
token.kind = ValueKind.ADDRESS | ||
token.data = address as u64 | ||
return token | ||
return new Value(ValueKind.ADDRESS, changetype<u32>(address)) | ||
} | ||
|
||
static fromBoolean(b: boolean): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.BOOL | ||
token.data = b ? 1 : 0 | ||
return token | ||
return new Value(ValueKind.BOOL, b ? 1 : 0) | ||
} | ||
|
||
static fromBytes(bytes: Bytes): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.BYTES | ||
token.data = bytes as u64 | ||
return token | ||
return new Value(ValueKind.BYTES, changetype<u32>(bytes)) | ||
} | ||
|
||
static fromFixedBytes(bytes: Bytes): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.FIXED_BYTES | ||
token.data = bytes as u64 | ||
return token | ||
return new Value(ValueKind.FIXED_BYTES, changetype<u32>(bytes)) | ||
} | ||
|
||
static fromI32(i: i32): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.INT | ||
token.data = BigInt.fromI32(i) as u64 | ||
return token | ||
return new Value(ValueKind.INT, changetype<u32>(BigInt.fromI32(i))) | ||
} | ||
|
||
static fromSignedBigInt(i: BigInt): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.INT | ||
token.data = i as u64 | ||
return token | ||
return new Value(ValueKind.INT, changetype<u32>(i)) | ||
} | ||
|
||
static fromUnsignedBigInt(i: BigInt): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.UINT | ||
token.data = i as u64 | ||
return token | ||
return new Value(ValueKind.UINT, changetype<u32>(i)) | ||
} | ||
|
||
static fromString(s: string): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.STRING | ||
token.data = s as u64 | ||
return token | ||
return new Value(ValueKind.STRING, changetype<u32>(s)) | ||
} | ||
|
||
static fromArray(values: Array<Value>): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.ARRAY | ||
token.data = values as u64 | ||
return token | ||
return new Value(ValueKind.ARRAY, changetype<u32>(values)) | ||
} | ||
|
||
static fromFixedSizedArray(values: Array<Value>): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.FIXED_ARRAY | ||
token.data = values as u64 | ||
return token | ||
return new Value(ValueKind.FIXED_ARRAY, changetype<u32>(values)) | ||
} | ||
|
||
static fromTuple(values: Tuple): Value { | ||
let token = new Value() | ||
token.kind = ValueKind.TUPLE | ||
token.data = values as u64 | ||
return token | ||
return new Value(ValueKind.TUPLE, changetype<u32>(values)) | ||
} | ||
|
||
static fromTupleArray(values: Array<Tuple>): Value { | ||
|
@@ -345,67 +327,67 @@ export namespace ethereum { | |
* An Ethereum block. | ||
*/ | ||
export class Block { | ||
hash: Bytes | ||
parentHash: Bytes | ||
unclesHash: Bytes | ||
author: Address | ||
stateRoot: Bytes | ||
transactionsRoot: Bytes | ||
receiptsRoot: Bytes | ||
number: BigInt | ||
gasUsed: BigInt | ||
gasLimit: BigInt | ||
timestamp: BigInt | ||
difficulty: BigInt | ||
totalDifficulty: BigInt | ||
size: BigInt | null | ||
hash!: Bytes | ||
parentHash!: Bytes | ||
unclesHash!: Bytes | ||
author!: Address | ||
stateRoot!: Bytes | ||
transactionsRoot!: Bytes | ||
receiptsRoot!: Bytes | ||
number!: BigInt | ||
gasUsed!: BigInt | ||
gasLimit!: BigInt | ||
timestamp!: BigInt | ||
difficulty!: BigInt | ||
totalDifficulty!: BigInt | ||
size!: BigInt | null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm what's the meaning of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because of this. Basically when the properties of an exported class don't have a constructor, it requires to either create one, or to add the I prefered this way instead of the constructors because as far as I know only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that annotating with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the warning! I guess I'll change it then 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A runtime check is inserted whenever a property annotated with |
||
} | ||
|
||
/** | ||
* An Ethereum transaction. | ||
*/ | ||
export class Transaction { | ||
hash: Bytes | ||
index: BigInt | ||
from: Address | ||
to: Address | null | ||
value: BigInt | ||
gasLimit: BigInt | ||
gasPrice: BigInt | ||
input: Bytes | ||
hash!: Bytes | ||
index!: BigInt | ||
from!: Address | ||
to!: Address | null | ||
value!: BigInt | ||
gasLimit!: BigInt | ||
gasPrice!: BigInt | ||
input!: Bytes | ||
} | ||
|
||
/** | ||
* Common representation for Ethereum smart contract calls. | ||
*/ | ||
export class Call { | ||
to: Address | ||
from: Address | ||
block: Block | ||
transaction: Transaction | ||
inputValues: Array<EventParam> | ||
outputValues: Array<EventParam> | ||
to!: Address | ||
from!: Address | ||
block!: Block | ||
transaction!: Transaction | ||
inputValues!: Array<EventParam> | ||
outputValues!: Array<EventParam> | ||
} | ||
|
||
/** | ||
* Common representation for Ethereum smart contract events. | ||
*/ | ||
export class Event { | ||
address: Address | ||
logIndex: BigInt | ||
transactionLogIndex: BigInt | ||
logType: string | null | ||
block: Block | ||
transaction: Transaction | ||
parameters: Array<EventParam> | ||
address!: Address | ||
logIndex!: BigInt | ||
transactionLogIndex!: BigInt | ||
logType!: string | null | ||
block!: Block | ||
transaction!: Transaction | ||
parameters!: Array<EventParam> | ||
} | ||
|
||
/** | ||
* A dynamically-typed Ethereum event parameter. | ||
*/ | ||
export class EventParam { | ||
name: string | ||
value: Value | ||
name!: string | ||
value!: Value | ||
} | ||
|
||
export class SmartContractCall { | ||
|
@@ -452,7 +434,7 @@ export namespace ethereum { | |
name + | ||
'` to handle this in the mapping.', | ||
) | ||
return result as Array<Value> | ||
return changetype<Array<Value>>(result) | ||
} | ||
|
||
tryCall( | ||
|
@@ -465,7 +447,7 @@ export namespace ethereum { | |
if (result == null) { | ||
return new CallResult() | ||
} else { | ||
return CallResult.fromValue(result as Array<Value>) | ||
return CallResult.fromValue(changetype<Array<Value>>(result)) | ||
} | ||
} | ||
} | ||
|
@@ -494,7 +476,7 @@ export namespace ethereum { | |
'accessed value of a reverted call, ' + | ||
'please check the `reverted` field before accessing the `value` field', | ||
) | ||
return (this._value as Wrapped<T>).inner | ||
return changetype<Wrapped<T>>(this._value).inner | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ended up a bit nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah haha 😄