@manahippo/move-to-ts
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -11,2 +11,4 @@ import bigInt from "big-integer"; | ||
checkBounds(): void; | ||
min(): bigInt.BigInteger; | ||
max(): bigInt.BigInteger; | ||
make(value: bigInt.BigInteger): UnsignedInt<T>; | ||
@@ -40,2 +42,4 @@ copy(): UnsignedInt<T>; | ||
checkBounds(): void; | ||
min(): bigInt.BigInteger; | ||
max(): bigInt.BigInteger; | ||
} | ||
@@ -47,2 +51,4 @@ export declare class U64 extends UnsignedInt<U64> { | ||
checkBounds(): void; | ||
min(): bigInt.BigInteger; | ||
max(): bigInt.BigInteger; | ||
} | ||
@@ -54,4 +60,6 @@ export declare class U128 extends UnsignedInt<U128> { | ||
checkBounds(): void; | ||
min(): bigInt.BigInteger; | ||
max(): bigInt.BigInteger; | ||
} | ||
export {}; | ||
//# sourceMappingURL=builtinTypes.d.ts.map |
@@ -22,3 +22,5 @@ import { HexString } from "aptos"; | ||
getFullname(): string; | ||
getShortAddressFullName(): string; | ||
getParamlessName(): string; | ||
getShortAddressParamlessName(): string; | ||
getAptosMoveTypeTag(): Types.MoveStructTag; | ||
@@ -44,3 +46,5 @@ } | ||
export declare function getTypeTagFullname(typeTag: TypeTag): string; | ||
export declare function getShortAddressTypeTagFullname(typeTag: TypeTag): string; | ||
export declare function getTypeTagParamlessName(typeTag: TypeTag): string; | ||
export declare function getShortAddressTypeTagParamlessName(typeTag: TypeTag): string; | ||
export declare function getTypeParamsString(typeParams: TypeTag[]): string; | ||
@@ -47,0 +51,0 @@ export declare function parseQualifiedStructTag(name: string): [null | StructTag, string]; |
{ | ||
"name": "@manahippo/move-to-ts", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
import { AptosClient, HexString, Types } from "aptos"; | ||
import { AptosParserRepo, StructInfoType } from "./parserRepo"; | ||
import { | ||
getTypeTagFullname, | ||
getShortAddressTypeTagFullname, | ||
parseMoveStructTag, | ||
@@ -132,3 +132,3 @@ StructTag, | ||
has(tag: TypeTag) { | ||
return this.resources.has(getTypeTagFullname(tag)); | ||
return this.resources.has(getShortAddressTypeTagFullname(tag)); | ||
} | ||
@@ -144,7 +144,7 @@ async has_async(tag: TypeTag, repo: AptosParserRepo, client: AptosClient) { | ||
get(tag: TypeTag) { | ||
const fullname = getTypeTagFullname(tag); | ||
const fullname = getShortAddressTypeTagFullname(tag); | ||
const resource = this.resources.get(fullname); | ||
if (!resource) { | ||
throw new Error( | ||
`Account ${this.address.hex()} does not have resource: ${fullname}` | ||
`Account ${this.address.toShortString()} does not have resource: ${fullname}` | ||
); | ||
@@ -166,3 +166,3 @@ } | ||
throw new Error( | ||
`Account ${this.address.hex()} does not have resource ${getTypeTagFullname( | ||
`Account ${this.address.toShortString()} does not have resource ${getShortAddressTypeTagFullname( | ||
tag | ||
@@ -174,6 +174,6 @@ )}` | ||
set(tag: TypeTag, resource: any, overwrite = false) { | ||
const fullname = getTypeTagFullname(tag); | ||
const fullname = getShortAddressTypeTagFullname(tag); | ||
if (this.has(tag) && !overwrite) { | ||
throw new Error( | ||
`Account ${this.address.hex()} already has resource: ${fullname}` | ||
`Account ${this.address.toShortString()} already has resource: ${fullname}` | ||
); | ||
@@ -184,7 +184,7 @@ } | ||
move_from(tag: TypeTag): any { | ||
const fullname = getTypeTagFullname(tag); | ||
const fullname = getShortAddressTypeTagFullname(tag); | ||
const resource = this.resources.get(fullname); | ||
if (!resource) { | ||
throw new Error( | ||
`Account ${this.address.hex()} does not have resource: ${fullname}` | ||
`Account ${this.address.toShortString()} does not have resource: ${fullname}` | ||
); | ||
@@ -200,3 +200,3 @@ } | ||
export class AptosLocalCache implements AptosDataCache { | ||
// maps account address (HexString.hex()) to AccountCache | ||
// maps account address (HexString.toShortString()) to AccountCache | ||
public accounts: Map<string, AccountCache>; | ||
@@ -212,3 +212,3 @@ public tables: Map<string, Map<string, IBox>>; | ||
exists(tag: TypeTag, address: HexString): boolean { | ||
const account = this.accounts.get(address.hex()); | ||
const account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
@@ -220,6 +220,6 @@ return false; | ||
move_to(tag: TypeTag, address: HexString, resource: any, overwrite = false): void { | ||
let account = this.accounts.get(address.hex()); | ||
let account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
account = new AccountCache(address); | ||
this.accounts.set(address.hex(), account); | ||
this.accounts.set(address.toShortString(), account); | ||
} | ||
@@ -232,8 +232,8 @@ account.set(tag, resource, overwrite); | ||
move_from<T>(tag: TypeTag, address: HexString): T { | ||
let account = this.accounts.get(address.hex()); | ||
let account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
throw new Error( | ||
`Resource ${getTypeTagFullname( | ||
`Resource ${getShortAddressTypeTagFullname( | ||
tag | ||
)} does not exist for ${address.hex()}` | ||
)} does not exist for ${address.toShortString()}` | ||
); | ||
@@ -244,8 +244,8 @@ } | ||
borrow_global<T>(tag: TypeTag, address: HexString): T { | ||
let account = this.accounts.get(address.hex()); | ||
let account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
throw new Error( | ||
`Resource ${getTypeTagFullname( | ||
`Resource ${getShortAddressTypeTagFullname( | ||
tag | ||
)} does not exist for ${address.hex()}` | ||
)} does not exist for ${address.toShortString()}` | ||
); | ||
@@ -288,3 +288,3 @@ } | ||
const newTable: Map<string, any> = new Map(); | ||
this.tables.set(handle.toString(), newTable); | ||
this.tables.set(handle.toShortString(), newTable); | ||
return newTable; | ||
@@ -298,3 +298,3 @@ } | ||
const table: Map<string, IBox> = new Map(); | ||
this.tables.set(handle.toString(), table); | ||
this.tables.set(handle.toShortString(), table); | ||
return handle; | ||
@@ -353,6 +353,6 @@ } | ||
async exists_async(tag: TypeTag, address: HexString): Promise<boolean> { | ||
let account = this.accounts.get(address.hex()); | ||
let account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
account = new AccountCache(address); | ||
this.accounts.set(address.hex(), account); | ||
this.accounts.set(address.toShortString(), account); | ||
} | ||
@@ -372,6 +372,6 @@ return account.has_async(tag, this.repo, this.client); | ||
async borrow_global_async<T>(tag: TypeTag, address: HexString): Promise<T> { | ||
let account = this.accounts.get(address.hex()); | ||
let account = this.accounts.get(address.toShortString()); | ||
if (!account) { | ||
account = new AccountCache(address); | ||
this.accounts.set(address.hex(), account); | ||
this.accounts.set(address.toShortString(), account); | ||
} | ||
@@ -584,3 +584,3 @@ return (await account.get_async( | ||
getResourceKey(ownerAddress: HexString, typeTag: TypeTag) { | ||
return `${ownerAddress.hex()}/${getTypeTagFullname(typeTag)}`; | ||
return `${ownerAddress.toShortString()}/${getShortAddressTypeTagFullname(typeTag)}`; | ||
} | ||
@@ -587,0 +587,0 @@ } |
@@ -30,2 +30,4 @@ import bigInt from "big-integer"; | ||
checkBounds() {} | ||
min() { return bigInt(); } | ||
max() { return bigInt(); } | ||
make(value: bigInt.BigInteger) { | ||
@@ -84,4 +86,3 @@ return new UnsignedInt<T>(value); | ||
shl(other: UnsignedInt<any>): UnsignedInt<T> { | ||
// FIXME: need to match this with move's implementation | ||
return this.make(this.value.shiftLeft(other.value)); | ||
return this.make(this.value.shiftLeft(other.value).and(this.max())); | ||
} | ||
@@ -125,2 +126,5 @@ shr(other: UnsignedInt<any>): UnsignedInt<T> { | ||
} | ||
min() { return U8.MIN; } | ||
max() { return U8.MAX; } | ||
} | ||
@@ -141,2 +145,5 @@ | ||
} | ||
min() { return U64.MIN; } | ||
max() { return U64.MAX; } | ||
} | ||
@@ -157,2 +164,5 @@ | ||
} | ||
min() { return U128.MIN; } | ||
max() { return U128.MAX; } | ||
} |
@@ -49,3 +49,3 @@ import { | ||
} | ||
if (typeTag.address.hex() !== struct.moduleAddress.hex()) { | ||
if (typeTag.address.toShortString() !== struct.moduleAddress.toShortString()) { | ||
throw new Error( | ||
@@ -52,0 +52,0 @@ `${struct.structName} expects a moduleAddress of ${struct.moduleAddress} but received: ${typeTag.address}.` |
@@ -30,2 +30,3 @@ import { HexString } from "aptos"; | ||
} | ||
getFullname(): string { | ||
@@ -38,2 +39,9 @@ const typeParamString = getTypeParamsString(this.typeParams); | ||
getShortAddressFullName() : string { | ||
const typeParamString = getTypeParamsString(this.typeParams); | ||
return `${this.address.toShortString()}::${this.module}::${ | ||
this.name | ||
}${typeParamString}`; | ||
} | ||
getParamlessName(): string { | ||
@@ -43,2 +51,7 @@ return `${this.address.hex()}::${this.module}::${this.name}`; | ||
getShortAddressParamlessName(): string { | ||
return `${this.address.toShortString()}::${this.module}::${this.name}`; | ||
} | ||
getAptosMoveTypeTag(): Types.MoveStructTag { | ||
@@ -86,3 +99,3 @@ return this.getFullname(); | ||
export function getTypeTagFullname(typeTag: TypeTag): string { | ||
function getTypeTagFullnameInner(typeTag: TypeTag, shortAddress: boolean): string { | ||
if (VectorTag.isInstance(typeTag)) { | ||
@@ -93,3 +106,4 @@ const vecTag = typeTag as VectorTag; | ||
const structTag = typeTag as StructTag; | ||
return structTag.getFullname(); | ||
return shortAddress ? | ||
structTag.getShortAddressFullName() : structTag.getFullname(); | ||
} else if (TypeParamIdx.isInstance(typeTag)) { | ||
@@ -105,3 +119,11 @@ return `$tv${typeTag.index}`; | ||
export function getTypeTagParamlessName(typeTag: TypeTag): string { | ||
export function getTypeTagFullname(typeTag: TypeTag): string { | ||
return getTypeTagFullnameInner(typeTag, false) | ||
} | ||
export function getShortAddressTypeTagFullname(typeTag: TypeTag): string { | ||
return getTypeTagFullnameInner(typeTag, true) | ||
} | ||
function getTypeTagParamlessNameInner(typeTag: TypeTag, shortAddress = false): string { | ||
if (VectorTag.isInstance(typeTag)) { | ||
@@ -111,3 +133,4 @@ return `vector`; | ||
const structTag = typeTag as StructTag; | ||
return structTag.getParamlessName(); | ||
return shortAddress ? | ||
structTag.getShortAddressParamlessName() : structTag.getParamlessName(); | ||
} else if (TypeParamIdx.isInstance(typeTag)) { | ||
@@ -123,2 +146,10 @@ return `$tv${typeTag.index}`; | ||
export function getTypeTagParamlessName(typeTag: TypeTag): string { | ||
return getTypeTagParamlessNameInner(typeTag, false) | ||
} | ||
export function getShortAddressTypeTagParamlessName(typeTag: TypeTag): string { | ||
return getTypeTagParamlessNameInner(typeTag, true) | ||
} | ||
export function getTypeParamsString(typeParams: TypeTag[]) { | ||
@@ -125,0 +156,0 @@ if (typeParams.length === 0) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
564207
9283