Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getStorage(contract: string, schema?: ContractSchema): Promise {
if (!schema) {
schema = await this.rpc.getScript(contract);
}
let contractSchema: Schema;
if (schema instanceof Schema) {
contractSchema = schema;
} else {
contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
}
const storage = await this.rpc.getStorage(contract);
return contractSchema.Execute(storage, smartContractAbstractionSemantic(this)) as T; // Cast into T because only the caller can know the true type of the storage
}
async getBigMapKey(contract: string, key: string, schema?: ContractSchema): Promise {
if (!schema) {
schema = await this.rpc.getScript(contract);
}
let contractSchema: Schema;
if (schema instanceof Schema) {
contractSchema = schema;
} else {
contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
}
const encodedKey = contractSchema.EncodeBigMapKey(key);
const val = await this.rpc.getBigMapKey(contract, encodedKey);
return contractSchema.ExecuteOnBigMapValue(val) as T; // Cast into T because only the caller can know the true type of the storage
}
async getBigMapKey(contract: string, key: string, schema?: ContractSchema): Promise {
if (!schema) {
schema = await this.rpc.getScript(contract);
}
let contractSchema: Schema;
if (schema instanceof Schema) {
contractSchema = schema;
} else {
contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
}
const encodedKey = contractSchema.EncodeBigMapKey(key);
const val = await this.rpc.getBigMapKey(contract, encodedKey);
return contractSchema.ExecuteOnBigMapValue(val) as T; // Cast into T because only the caller can know the true type of the storage
}
async getStorage(contract: string, schema?: ContractSchema): Promise {
if (!schema) {
schema = await this.rpc.getScript(contract);
}
let contractSchema: Schema;
if (schema instanceof Schema) {
contractSchema = schema;
} else {
contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
}
const storage = await this.rpc.getStorage(contract);
return contractSchema.Execute(storage, smartContractAbstractionSemantic(this)) as T; // Cast into T because only the caller can know the true type of the storage
}
constructor(
public readonly address: string,
public readonly script: ScriptResponse,
private provider: ContractProvider,
private entrypoints?: EntrypointsResponse
) {
this.schema = Schema.fromRPCResponse({ script: this.script });
this.parameterSchema = ParameterSchema.fromRPCResponse({ script: this.script });
if (!this.entrypoints) {
this._initializeMethodsLegacy(address, provider);
} else {
this._initializeMethods(address, provider, this.entrypoints.entrypoints);
}
}