@graphprotocol/graph-ts
Advanced tools
Comparing version 0.0.1 to 0.3.2
166
index.ts
@@ -51,2 +51,14 @@ // Export allocator functions for hosts to manage WASM memory | ||
function bigIntToInt256(i: BigInt): U64Array | ||
// Primitive to/from ethereum 256-bit number conversions. | ||
function u64ToU256(x: u64): U64Array | ||
function i64ToU256(x: i64): U64Array | ||
function u256ToU8(x: U64Array): u8 | ||
function u256ToU16(x: U64Array): u16 | ||
function u256ToU32(x: U64Array): u32 | ||
function u256ToU64(x: U64Array): u64 | ||
function u256ToI8(x: U64Array): i8 | ||
function u256ToI16(x: U64Array): i16 | ||
function u256ToI32(x: U64Array): i32 | ||
function u256ToI64(x: U64Array): i64 | ||
} | ||
@@ -159,4 +171,25 @@ | ||
/** A signed 256-bit integer. */ | ||
export class I256 extends U64Array {} | ||
export class I256 extends U64Array { | ||
static fromI64(x: i64): I256 { | ||
return changetype<I256>(typeConversion.i64ToU256(x)) | ||
} | ||
toI8(): i8 { | ||
return typeConversion.u256ToI8(this) | ||
} | ||
toI16(): i16 { | ||
return typeConversion.u256ToI16(this) | ||
} | ||
toI32(): i32 { | ||
return typeConversion.u256ToI32(this) | ||
} | ||
toI64(): i64 { | ||
return typeConversion.u256ToI64(this) | ||
} | ||
} | ||
/** An unsigned 128-bit integer. */ | ||
@@ -166,4 +199,25 @@ export class U128 extends U64Array {} | ||
/** An unsigned 256-bit integer. */ | ||
export class U256 extends U64Array {} | ||
export class U256 extends U64Array { | ||
static fromU64(x: u64): U256 { | ||
return changetype<U256>(typeConversion.u64ToU256(x)) | ||
} | ||
toU8(): u8 { | ||
return typeConversion.u256ToU8(this) | ||
} | ||
toU16(): u16 { | ||
return typeConversion.u256ToU16(this) | ||
} | ||
toU32(): u32 { | ||
return typeConversion.u256ToU32(this) | ||
} | ||
toU64(): u64 { | ||
return typeConversion.u256ToU64(this) | ||
} | ||
} | ||
/** Type hint for Ethereum values. */ | ||
@@ -228,6 +282,7 @@ export enum EthereumValueKind { | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int.' | ||
) | ||
return this.data as i8 | ||
let i256 = changetype<I256>(this.data as u32) | ||
return i256.toI8() | ||
} | ||
@@ -237,6 +292,7 @@ | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int.' | ||
) | ||
return this.data as i16 | ||
let i256 = changetype<I256>(this.data as u32) | ||
return i256.toI16() | ||
} | ||
@@ -246,11 +302,21 @@ | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int.' | ||
) | ||
return this.data as i32 | ||
let i256 = changetype<I256>(this.data as u32) | ||
return i256.toI32() | ||
} | ||
toI64(): i64 { | ||
assert( | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int.' | ||
) | ||
let i256 = changetype<I256>(this.data as u32) | ||
return i256.toI64() | ||
} | ||
toI128(): I128 { | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int or uint.' | ||
@@ -263,4 +329,4 @@ ) | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.INT, | ||
'EthereumValue is not an int.' | ||
) | ||
@@ -272,6 +338,7 @@ return changetype<I256>(this.data as u32) | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an uint.' | ||
) | ||
return this.data as u8 | ||
let u256 = changetype<U256>(this.data as u32) | ||
return u256.toU8() | ||
} | ||
@@ -281,6 +348,7 @@ | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an uint.' | ||
) | ||
return this.data as u16 | ||
let u256 = changetype<U256>(this.data as u32) | ||
return u256.toU16() | ||
} | ||
@@ -290,8 +358,18 @@ | ||
assert( | ||
this.kind == EthereumValueKind.INT || this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an int or uint.' | ||
this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an uint.' | ||
) | ||
return this.data as u32 | ||
let u256 = changetype<U256>(this.data as u32) | ||
return u256.toU32() | ||
} | ||
toU64(): u64 { | ||
assert( | ||
this.kind == EthereumValueKind.UINT, | ||
'EthereumValue is not an uint.' | ||
) | ||
let u256 = changetype<U256>(this.data as u32) | ||
return u256.toU64() | ||
} | ||
toU128(): U128 { | ||
@@ -372,3 +450,3 @@ assert( | ||
token.kind = EthereumValueKind.INT | ||
token.data = i as u64 | ||
token.data = I256.fromI64(i as i64) as u64 | ||
return token | ||
@@ -380,3 +458,3 @@ } | ||
token.kind = EthereumValueKind.INT | ||
token.data = i as u64 | ||
token.data = I256.fromI64(i as i64) as u64 | ||
return token | ||
@@ -388,6 +466,13 @@ } | ||
token.kind = EthereumValueKind.INT | ||
token.data = i as u64 | ||
token.data = I256.fromI64(i as i64) as u64 | ||
return token | ||
} | ||
static fromI64(i: i64): EthereumValue { | ||
let token = new EthereumValue() | ||
token.kind = EthereumValueKind.INT | ||
token.data = I256.fromI64(i) as u64 | ||
return token | ||
} | ||
static fromI128(i: I128): EthereumValue { | ||
@@ -410,3 +495,3 @@ let token = new EthereumValue() | ||
token.kind = EthereumValueKind.UINT | ||
token.data = u as u64 | ||
token.data = U256.fromU64(u as u64) as u64 | ||
return token | ||
@@ -418,3 +503,3 @@ } | ||
token.kind = EthereumValueKind.UINT | ||
token.data = u as u64 | ||
token.data = U256.fromU64(u as u64) as u64 | ||
return token | ||
@@ -426,6 +511,13 @@ } | ||
token.kind = EthereumValueKind.UINT | ||
token.data = u as u64 | ||
token.data = U256.fromU64(u as u64) as u64 | ||
return token | ||
} | ||
static fromU64(u: u64): EthereumValue { | ||
let token = new EthereumValue() | ||
token.kind = EthereumValueKind.UINT | ||
token.data = U256.fromU64(u) as u64 | ||
return token | ||
} | ||
static fromU128(u: U128): EthereumValue { | ||
@@ -508,5 +600,5 @@ let token = new EthereumValue() | ||
toU32(): u32 { | ||
assert(this.kind == ValueKind.INT, 'Value is not an u32.') | ||
return this.data as u32 | ||
toI32(): i32 { | ||
assert(this.kind == ValueKind.INT, 'Value is not an i32.') | ||
return this.data as i32 | ||
} | ||
@@ -575,3 +667,3 @@ | ||
static fromU32(n: u32): Value { | ||
static fromI32(n: i32): Value { | ||
let value = new Value() | ||
@@ -627,4 +719,4 @@ value.kind = ValueKind.INT | ||
getU32(key: string): u32 { | ||
return this.get(key).toU32() | ||
getI32(key: string): i32 { | ||
return this.get(key).toI32() | ||
} | ||
@@ -652,4 +744,4 @@ | ||
setInt(key: string, value: u32): void { | ||
this.set(key, Value.fromU32(value)) | ||
setInt(key: string, value: i32): void { | ||
this.set(key, Value.fromI32(value)) | ||
} | ||
@@ -656,0 +748,0 @@ |
{ | ||
"name": "@graphprotocol/graph-ts", | ||
"description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph", | ||
"version": "0.0.1", | ||
"version": "0.3.2", | ||
"module": "index.ts", | ||
@@ -6,0 +6,0 @@ "types": "index.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38093
8
762