Socket
Socket
Sign inDemoInstall

@neo-one/smart-contract

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@neo-one/smart-contract - npm Package Compare versions

Comparing version 1.0.0-alpha.25 to 1.0.0-alpha.26

2

package.json
{
"name": "@neo-one/smart-contract",
"version": "1.0.0-alpha.25",
"version": "1.0.0-alpha.26",
"author": "Alex DiCarlo <alexdicarlo@gmail.com>",

@@ -5,0 +5,0 @@ "description": "NEO•ONE smart contract apis.",

// tslint:disable
interface Boolean {}
interface BooleanConstructor {}
/**
* Marks an interface or class as not implementable or extendable.
*
* Makes it an error to pass values that would otherwise match the shape of the interface.
*
* See <fill_me_in> for more info.
*/
declare const one0: unique symbol;
/**
* Marks an interface or class as not implementable or extendable.
*
* Makes it an error to pass values that would otherwise match the shape of the interface.
*
* See <fill_me_in> for more info.
*/
declare const one1: unique symbol;
interface Boolean {
readonly [one0]: unique symbol;
}
interface BooleanConstructor {
readonly [one0]: unique symbol;
}
declare const Boolean: BooleanConstructor;
interface Number {}
interface NumberConstructor {}
interface Number {
readonly [one0]: unique symbol;
}
interface NumberConstructor {
readonly [one0]: unique symbol;
}
declare const Number: NumberConstructor;
interface String {}
interface StringConstructor {}
interface String {
readonly [one0]: unique symbol;
}
interface StringConstructor {
readonly [one0]: unique symbol;
}
declare const String: StringConstructor;
interface Function {}
interface FunctionConstructor {}
interface FunctionConstructor {
readonly [one0]: unique symbol;
}
declare const Function: FunctionConstructor;
interface IArguments {}
interface IArguments {
readonly [one0]: unique symbol;
}

@@ -26,21 +59,28 @@ interface Object {}

*/
keys(o: {}): string[];
readonly keys: (o: {}) => string[];
readonly [one0]: unique symbol;
}
declare const Object: ObjectConstructor;
interface RegExp {}
interface RegExpConstructor {}
interface RegExp {
readonly [one0]: unique symbol;
}
interface RegExpConstructor {
readonly [one0]: unique symbol;
}
declare const RegExp: RegExpConstructor;
interface Error {
message: string;
readonly message: string;
readonly [one0]: unique symbol;
}
interface ErrorPrototype {}
interface ErrorConstructor {
new (message?: string): Error;
readonly prototype: ErrorPrototype;
readonly [one0]: unique symbol;
}
declare const Error: ErrorConstructor;
interface Symbol {}
interface Symbol {
readonly [one0]: unique symbol;
}
interface SymbolConstructor {

@@ -52,3 +92,3 @@ /**

*/
for(key: string): symbol;
readonly for: (key: string) => symbol;
/**

@@ -64,2 +104,3 @@ * A method that returns the default iterator for an object. Called by the semantics of the

readonly toPrimitive: symbol;
readonly [one0]: unique symbol;
}

@@ -75,4 +116,5 @@ declare var Symbol: SymbolConstructor;

readonly length: number;
equals(otherBuffer: Buffer): boolean;
toString(encoding: 'utf8'): string;
readonly equals: (otherBuffer: Buffer) => boolean;
readonly toString: (encoding: 'utf8') => string;
readonly [one0]: unique symbol;
}

@@ -85,3 +127,3 @@ interface BufferConstructor {

*/
from(str: string, encoding?: BufferEncoding): Buffer;
readonly from: (str: string, encoding?: BufferEncoding) => Buffer;
/**

@@ -95,3 +137,4 @@ * Returns a buffer which is the result of concatenating all the buffers in the list together.

*/
concat(list: Buffer[]): Buffer;
readonly concat: (list: Buffer[]) => Buffer;
readonly [one0]: unique symbol;
}

@@ -109,3 +152,4 @@ /**

*/
log(message?: any, ...optionalParams: any[]): void;
readonly log: (message?: any, ...optionalParams: any[]) => void;
readonly [one0]: unique symbol;
}

@@ -116,21 +160,24 @@

interface IteratorResult<T> {
done: boolean;
value: T;
readonly done: boolean;
readonly value: T;
readonly [one0]: unique symbol;
}
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
readonly next: (value?: any) => IteratorResult<T>;
readonly [one0]: unique symbol;
}
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
readonly [Symbol.iterator]: () => Iterator<T>;
readonly [one0]: Iterator<T>[typeof one0];
}
interface IterableIterator<T> extends Iterator<T> {
[Symbol.iterator](): IterableIterator<T>;
readonly [Symbol.iterator]: () => IterableIterator<T>;
readonly [one1]: unique symbol;
}
interface Array<T> {
interface ReadonlyArray<T> extends Iterable<T> {
readonly [Symbol.iterator]: () => IterableIterator<T>;
/**

@@ -140,16 +187,50 @@ * Gets the length of the array. This is a number one higher than the highest element defined in an array.

readonly length: number;
/** Iterator */
[Symbol.iterator](): IterableIterator<T>;
/**
* Returns an iterable of key, value pairs for every entry in the array
*/
readonly entries: () => IterableIterator<[number, T]>;
/**
* Returns a string representation of an array.
*/
readonly toString: () => string;
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
readonly concat: {
<T>(...items: ConcatArray<T>[]): T[];
<T>(...items: T[]): T[];
<T>(...items: (T | ConcatArray<T>)[]): T[];
};
/**
* Adds all the elements of an array separated by the specified separator string.
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
*/
readonly join: (separator?: string) => string;
/**
* Returns a section of an array.
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array.
*/
readonly slice: (start?: number, end?: number) => T[];
/**
* Determines whether all the members of an array satisfy the specified test.
* @param callbackfn A function that accepts up to two arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
*/
readonly every: (callbackfn: (value: T, index: number) => boolean) => boolean;
/**
* Determines whether the specified callback function returns true for any element of an array.
* @param callbackfn A function that accepts up to two arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
*/
readonly some: (callbackfn: (value: T, index: number) => boolean) => boolean;
/**
* Performs the specified action for each element in an array.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
* @param callbackfn A function that accepts up to two arguments. forEach calls the callbackfn function one time for each element in the array.
*/
forEach(callbackfn: (value: T, index: number) => void): void;
readonly forEach: (callbackfn: (value: T, index: number) => void) => void;
/**
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
* @param callbackfn A function that accepts up to two arguments. The map method calls the callbackfn function one time for each element in the array.
*/
map<U>(callbackfn: (value: T, index: number) => U): U[];
readonly map: <U>(callbackfn: (value: T, index: number) => U) => U[];
/**

@@ -160,5 +241,77 @@ * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T): T;
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T;
readonly reduce: {
(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T;
<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U;
};
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to two arguments. The filter method calls the callbackfn function one time for each element in the array.
*/
readonly filter: {
<S extends T>(callbackfn: (value: T, index: number) => value is S): S[];
(callbackfn: (value: T, index: number) => any): T[];
};
readonly [n: number]: T;
readonly [one1]: unique symbol;
}
type ConcatArray<T> = Array<T> | ReadonlyArray<T>;
interface Array<T> extends Iterable<T> {
readonly [Symbol.iterator]: () => IterableIterator<T>;
/**
* Gets the length of the array. This is a number one higher than the highest element defined in an array.
*/
readonly length: number;
/**
* Returns an iterable of key, value pairs for every entry in the array
*/
readonly entries: () => IterableIterator<[number, T]>;
/**
* Returns a string representation of an array.
*/
readonly toString: () => string;
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
readonly concat: {
<T>(...items: ConcatArray<T>[]): T[];
<T>(...items: T[]): T[];
<T>(...items: (T | ConcatArray<T>)[]): T[];
};
/**
* Adds all the elements of an array separated by the specified separator string.
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
*/
readonly join: (separator?: string) => string;
/**
* Returns a section of an array.
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array.
*/
readonly slice: (start?: number, end?: number) => T[];
/**
* Determines whether all the members of an array satisfy the specified test.
* @param callbackfn A function that accepts up to two arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
*/
readonly every: (callbackfn: (value: T, index: number) => boolean) => boolean;
/**
* Determines whether the specified callback function returns true for any element of an array.
* @param callbackfn A function that accepts up to two arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
*/
readonly some: (callbackfn: (value: T, index: number) => boolean) => boolean;
/**
* Performs the specified action for each element in an array.
* @param callbackfn A function that accepts up to two arguments. forEach calls the callbackfn function one time for each element in the array.
*/
readonly forEach: (callbackfn: (value: T, index: number) => void) => void;
/**
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
* @param callbackfn A function that accepts up to two arguments. The map method calls the callbackfn function one time for each element in the array.
*/
readonly map: <U>(callbackfn: (value: T, index: number) => U) => U[];
// Writable only because it causes wonkiness with tsc otherwise
/**
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

@@ -168,21 +321,40 @@ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T;
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U;
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
* @param callbackfn A function that accepts up to two arguments. The filter method calls the callbackfn function one time for each element in the array.
*/
filter(callbackfn: (value: T, index: number) => any): T[];
readonly filter: {
<S extends T>(callbackfn: (value: T, index: number) => value is S): S[];
(callbackfn: (value: T, index: number) => any): T[];
};
/**
* Removes the last element from an array and returns it.
*/
readonly pop: () => T | undefined;
// Writable only because it causes wonkiness with tsc otherwise
/**
* Appends new elements to an array, and returns the new length of the array.
* @param items New elements of the Array.
*/
push(...items: T[]): number;
[n: number]: T;
readonly [one1]: ReadonlyArray<T>[typeof one1];
}
interface ArrayConstructor {}
interface ArrayConstructor {
readonly [one0]: unique symbol;
}
declare const Array: ArrayConstructor;
interface Map<K, V> {
clear(): void;
delete(key: K): boolean;
get(key: K): V | undefined;
set(key: K, value: V): this;
interface Map<K, V> extends Iterable<[K, V]> {
readonly [Symbol.iterator]: () => IterableIterator<[K, V]>;
readonly forEach: (callbackfn: (value: V, key: K) => void) => void;
readonly get: (key: K) => V | undefined;
readonly has: (key: K) => boolean;
readonly size: number;
readonly delete: (key: K) => boolean;
readonly set: (key: K, value: V) => this;
readonly [one1]: ReadonlyMap<K, V>[typeof one1];
}

@@ -192,5 +364,38 @@ interface MapConstructor {

readonly prototype: Map<any, any>;
readonly [one0]: unique symbol;
}
declare var Map: MapConstructor;
interface ReadonlyMap<K, V> extends Iterable<[K, V]> {
readonly [Symbol.iterator]: () => IterableIterator<[K, V]>;
readonly forEach: (callbackfn: (value: V, key: K) => void) => void;
readonly get: (key: K) => V | undefined;
readonly has: (key: K) => boolean;
readonly size: number;
readonly [one1]: unique symbol;
}
interface Set<T> extends Iterable<T> {
readonly [Symbol.iterator]: () => IterableIterator<T>;
readonly forEach: (callbackfn: (value: T) => void) => void;
readonly has: (value: T) => boolean;
readonly size: number;
readonly delete: (value: T) => boolean;
readonly add: (value: T) => this;
readonly [one1]: ReadonlySet<T>[typeof one1];
}
interface SetConstructor {
new <T = any>(values?: ReadonlyArray<T>): Set<T>;
readonly prototype: Set<any>;
}
declare var Set: SetConstructor;
interface ReadonlySet<T> extends Iterable<T> {
readonly [Symbol.iterator]: () => IterableIterator<T>;
readonly forEach: (callbackfn: (value: T) => void) => void;
readonly has: (value: T) => boolean;
readonly size: number;
readonly [one1]: unique symbol;
}
interface PropertyDescriptor {

@@ -197,0 +402,0 @@ configurable?: boolean;

// tslint:disable
/// <reference path="./global.d.ts" />
/// <reference path="./internal.d.ts" />
declare const OpaqueTagSymbol: unique symbol;
/**
* Marks an interface or class as not implementable or extendable.
*
* Makes it an error to pass values that would otherwise match the shape of the interface.
*
* See <fill_me_in> for more info.
*/
declare const OpaqueTagSymbol0: unique symbol;

@@ -13,3 +19,3 @@ /**

export interface Address extends Buffer {
readonly [OpaqueTagSymbol]: unique symbol;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -33,15 +39,30 @@ export interface AddressConstructor {

/**
* Verifies that the invocation was directly called AND approved by `Address`.
*
* Smart contracts should invoke this function before taking transferring items for `Address`es, like transferring tokens, that require the permission of the `Address`.
*
* @example
*
* if (!Address.isCaller(address)) {
* return false;
* }
*
* @returns true if `Address` approves this invocation.
*/
readonly isCaller: (address: Address) => boolean;
/**
* Verifies that the `Transaction` was signed by the `address`.
*
* Smart contracts should invoke this function before taking actions on `Address`es, like transferring tokens, that require the permission of the `Address`.
* In most cases, smart contracts should instead use `Address.isCaller`.
*
* @example
*
* if (!Address.verifySender(address)) {
* if (!Address.isSender(address)) {
* return false;
* }
*
* @returns true if `Address` approved this `Transaction`
* @returns true if `Address` signed this `Transaction`
*/
readonly verifySender: (address: Address) => boolean;
readonly isSender: (address: Address) => boolean;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -56,3 +77,3 @@ export const Address: AddressConstructor;

export interface Hash256 extends Buffer {
readonly [OpaqueTagSymbol]: unique symbol;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -79,2 +100,3 @@ export interface Hash256Constructor {

readonly GAS: Hash256;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -87,3 +109,3 @@ export const Hash256: Hash256Constructor;

export interface PublicKey extends Buffer {
readonly [OpaqueTagSymbol]: unique symbol;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -102,2 +124,3 @@ export interface PublicKeyConstructor {

readonly from: (value: string) => PublicKey;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -294,4 +317,7 @@ export const PublicKey: PublicKeyConstructor;

readonly data: Buffer;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface AttributeBaseConstructor {}
export interface AttributeBaseConstructor {
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const AttributeBase: AttributeBaseConstructor;

@@ -352,4 +378,7 @@

readonly value: Fixed8;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface OutputConstructor {}
export interface OutputConstructor {
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const Output: OutputConstructor;

@@ -369,4 +398,7 @@

readonly index: Integer;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface InputConstructor {}
export interface InputConstructor {
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const Input: InputConstructor;

@@ -417,2 +449,3 @@

readonly unspentOutputs: Output[];
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -509,2 +542,3 @@ export interface TransactionBaseConstructor {}

readonly for: (hash: Hash256) => Transaction;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -532,2 +566,3 @@ export const Transaction: TransactionConstructor;

readonly getBalance: (asset: Hash256) => Fixed8;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -539,2 +574,3 @@ export interface AccountConstructor {

readonly for: (address: Address) => Account;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -605,2 +641,3 @@ export const Account: AccountConstructor;

readonly issuer: Address;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -612,2 +649,3 @@ export interface AssetConstructor {

readonly for: (hash: Hash256) => Asset;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -635,2 +673,3 @@ export const Asset: AssetConstructor;

readonly payable: boolean;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -644,2 +683,3 @@ export interface ContractConstructor {

readonly for: (address: Address) => Contract | undefined;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -683,2 +723,3 @@ export const Contract: ContractConstructor;

readonly nextConsensus: Address;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -692,2 +733,3 @@ export interface HeaderConstructor {

readonly for: (hashOrIndex: Hash256 | Integer) => Header;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -716,6 +758,13 @@ export const Header: HeaderConstructor;

readonly for: (hashOrIndex: Hash256 | Integer) => Block;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const Block: BlockConstructor;
export type SerializableKey =
export type SerializableKeySingle = number | string | boolean | Buffer;
type SK = SerializableKeySingle;
export type SerializableKey = SK | [SK, SK] | [SK, SK, SK] | [SK, SK, SK, SK];
interface SerializableValueArray extends ReadonlyArray<SerializableValue> {}
interface SerializableValueMap extends ReadonlyMap<SerializableKeySingle, SerializableValue> {}
interface SerializableValueSet extends ReadonlySet<SerializableValue> {}
export type SerializableValue =
| undefined

@@ -726,17 +775,76 @@ | number

| Buffer
| Array<undefined | number | string | boolean | Buffer>;
interface SerializableValueArray extends Array<SerializableValue> {}
export type SerializableValue = undefined | number | string | boolean | Buffer | SerializableValueArray;
| SerializableValueArray
| SerializableValueMap
| SerializableValueSet;
/**
* Persistent smart contract storage. When used as a `SmartContract` property the prefix is automatically set to the property name.
* Persistent smart contract set storage. Only usable as a `SmartContract` property.
*
* @example
*
* class Token implements SmartContract {
* class MySmartContract extends SmartContract {
* private readonly pendingAddresses =
* ArrayStorage.for<Address>();
*
* public addPendingAddress(address: Address): void {
* this.pendingAddresses.push(address);
* }
* }
*
*/
export interface ArrayStorage<T extends SerializableValue> extends Iterable<T> {
readonly [Symbol.iterator]: () => IterableIterator<T>;
/**
* Gets the length of the array. This is a number one higher than the highest element defined in an array.
*/
readonly length: number;
/**
* Executes a provided function once per each value in storage.
* @param callback function to execute for each element.
* @returns `undefined`
*/
readonly forEach: (callback: (value: T, idx: number) => void) => void;
/**
* Appends new elements to storage, and returns the new length of the array.
* @param items New elements to add.
*/
readonly push: (...items: T[]) => number;
/**
* Removes the last element from an array and returns it.
*/
readonly pop: () => T | undefined;
[n: number]: T;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface ArrayStorageConstructor {
/**
* Constructs a new `ArrayStorage` instance. Only usable as a `SmartContract` property.
*/
for<T extends SerializableValue>(): ArrayStorage<T>;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const ArrayStorage: ArrayStorageConstructor;
type SKMapAtTwo<K extends [SK, SK], V extends SerializableValue> = {
(prefix: K[0]): MapStorage<K[1], V>;
};
type SKMapAtThree<K extends [SK, SK, SK], V extends SerializableValue> = {
(prefix: K[0]): MapStorage<[K[1], K[2]], V>;
(prefix: [K[0], K[1]]): MapStorage<K[2], V>;
};
type SKMapAtFour<K extends [SK, SK, SK, SK], V extends SerializableValue> = {
(prefix: K[0]): MapStorage<[K[1], K[2], K[3]], V>;
(prefix: [K[0], K[1]]): MapStorage<[K[2], K[3]], V>;
(prefix: [K[0], K[1], K[2]]): MapStorage<K[3], V>;
};
/**
* Persistent smart contract storage. Only usable as a `SmartContract` property.
*
* @example
*
* class Token extends SmartContract {
* private readonly balances =
* new MapStorage<Address, Fixed<8>>();
* MapStorage.for<Address, Fixed<8>>();
*
* // Note this is not how one should implement token transfer
* // and is meant for illustration purposes only.
* public transfer(

@@ -756,36 +864,76 @@ * from: Address,

*/
export interface MapStorage<K extends SerializableKey, V extends SerializableValue> {
export interface MapStorage<K extends SerializableKey, V extends SerializableValue> extends Iterable<[K, V]> {
readonly [Symbol.iterator]: () => IterableIterator<[K, V]>;
/**
* Retrieve `key` from storage.
*
* @returns `V` or undefined if the key does not exist.
* Executes a provided function once per each key/value pair in storage.
* @param callback function to execute for each element.
* @returns `undefined`
*/
readonly forEach: (callback: (value: V, key: K) => void) => void;
/**
* Returns a specified element from storage.
* @param key the key of the element to return from storage.
* @returns the element associated with the specified key or undefined if the key can't be found in storage.
*/
readonly get: (key: K) => V | undefined;
/**
* Set `key` to `value` in storage.
* Returns a boolean indicating whether an element with the specified key exists or not.
* @param key the key of the element to test for presence in storage.
* @returns `true` if an element with the specified key exists in storage; otherwise `false`.
*/
readonly set: (key: K, v: V) => void;
readonly has: (key: K) => boolean;
/**
* Delete `key` from storage.
* Removes the specified element from storage.
* @returns `true` if an element in storage existed and has been removed, or `false` if the element does not exist.
*/
readonly delete: (key: K) => void;
readonly delete: (key: K) => boolean;
/**
* Adds or updates an element with a specified key and value in storage.
* @param key The key of the element to add to storage.
* @param value The value of the element to add to storage.
* @returns the `MapStorage` object.
*/
readonly set: (key: K, value: V) => MapStorage<K, V>;
/**
* Returns the elements from storage with the specified prefix.
* @param key The prefix key of desired elements from storage.
* @returns a `MapStorage` object representing the elements associated with the specified prefix.
*/
readonly at: K extends [SK, SK]
? SKMapAtTwo<K, V>
: K extends [SK, SK, SK] ? SKMapAtThree<K, V> : K extends [SK, SK, SK, SK] ? SKMapAtFour<K, V> : never;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface MapStorageConstructor {
/**
* Constructs a new `MapStorage` instance. When used as a `SmartContract` property the `prefix` is automatically set to the property name. Otherwise, `prefix` is mandatory and should be unique within a smart contract.
* Constructs a new `MapStorage` instance. Only usable as a `SmartContract` property.
*/
new <K extends SerializableKey, V extends SerializableValue>(prefix?: Buffer): MapStorage<K, V>;
for<K extends SerializableKey, V extends SerializableValue>(): MapStorage<K, V>;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export const MapStorage: MapStorageConstructor;
type SKSetAtTwo<V extends [SK, SK]> = {
(prefix: V[0]): SetStorage<V[1]>;
};
type SKSetAtThree<V extends [SK, SK, SK]> = {
(prefix: V[0]): SetStorage<[V[1], V[2]]>;
(prefix: [V[0], V[1]]): SetStorage<V[2]>;
};
type SKSetAtFour<V extends [SK, SK, SK, SK]> = {
(prefix: V[0]): SetStorage<[V[1], V[2], V[3]]>;
(prefix: [V[0], V[1]]): SetStorage<[V[2], V[3]]>;
(prefix: [V[0], V[1], V[2]]): SetStorage<V[3]>;
};
/**
* Persistent smart contract set storage. When used as a `SmartContract` property the prefix is automatically set to the property name.
* Persistent smart contract set storage. Only usable as a `SmartContract` property.
*
* @example
*
* class ICO implements SmartContract {
* class ICO extends SmartContract {
* private readonly whitelistedAddresses =
* new SetStorage<Address>();
* SetStorage.for<Address>();
*
* public isWhitelisted(adress: Address): boolean {
* public isWhitelisted(address: Address): boolean {
* return this.whitelistedAddresses.has(address);

@@ -796,21 +944,43 @@ * }

*/
export interface SetStorage<V extends SerializableKey> {
export interface SetStorage<V extends SerializableKey> extends Iterable<V> {
readonly [Symbol.iterator]: () => IterableIterator<V>;
/**
* @returns true if `value` exists in storage.
* Executes a provided function once per each value in storage.
* @param callback function to execute for each element.
* @returns `undefined`
*/
readonly forEach: (callback: (value: V) => void) => void;
/**
* Returns a boolean indicating whether an element with the specified value exists or not.
* @param value the value to test for presence in storage.
* @returns `true` if an element with the specified value exists in storage; otherwise `false`.
*/
readonly has: (value: V) => boolean;
/**
* Add `value` to storage.
* Removes the specified element from storage.
* @returns `true` if an element in storage existed and has been removed, or `false` if the element does not exist.
*/
readonly add: (value: V) => void;
readonly delete: (value: V) => boolean;
/**
* Delete `value` from storage.
* Adds an element with the specified value in storage.
* @param value The value of the element to add to storage.
* @returns the `SetStorage` object.
*/
readonly delete: (value: V) => void;
readonly add: (value: V) => SetStorage<V>;
/**
* Returns the elements from storage with the specified prefix.
* @param key The prefix key of desired elements from storage.
* @returns a `SetStorage` object representing the elements associated with the specified prefix.
*/
readonly at: V extends [SK, SK]
? SKSetAtTwo<V>
: V extends [SK, SK, SK] ? SKSetAtThree<V> : V extends [SK, SK, SK, SK] ? SKSetAtFour<V> : never;
readonly [OpaqueTagSymbol0]: unique symbol;
}
export interface SetStorageConstructor {
/**
* Constructs a new `SetStorage` instance. When used as a `SmartContract` property the `prefix` is automatically set to the property name. Otherwise, `prefix` is mandatory and should be unique within a smart contract.
* Constructs a new `SetStorage` instance. Only usable as a `SmartContract` property.
*/
new <K extends SerializableKey>(prefix?: Buffer): SetStorage<K>;
for<K extends SerializableKey>(): SetStorage<K>;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -835,6 +1005,3 @@ export const SetStorage: SetStorageConstructor;

readonly currentTransaction: InvocationTransaction;
/**
* `Address` of the smart contract.
*/
readonly contractAddress: Address;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -853,7 +1020,10 @@ /**

*
* class Token implements SmartContract {
* public constructor(public readonly owner: Address = Deploy.senderAddress) {}
* class Token extends SmartContract {
* public constructor(public readonly owner: Address = Deploy.senderAddress) {
* super();
* }
* }
*/
readonly senderAddress: Address;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -885,3 +1055,3 @@ /**

: never
: T[K]
: T[K] extends SmartContractValue ? T[K] : never
};

@@ -951,50 +1121,37 @@

readonly description: string;
readonly payable: boolean;
}
/**
* Marks a class as a `SmartContract`.
*/
export interface SmartContract {
export abstract class SmartContract {
/**
* Owner of the `SmartContract`
* Properties used for deployment of the `SmartContract`
*/
owner: Address;
public abstract readonly properties: ContractProperties;
/**
* Properties used for deployment of the `SmartContract`
* `Address` of the `SmartContract`.
*/
readonly properties: ContractProperties;
}
export interface SmartContractConstructor {
public readonly address: Address;
/**
* Returns an object representing a contract at `address` with the given type `T`.
* Stores `Transaction` hashes that have been processed by a method marked with `@receive` or `@send`.
*
* `T` is checked for validity and `getSmartContract` will report an error during compilation if the interface is invalid.
*
* @example
*
* interface TransferContract {
* transfer(from: Address, to: Address, value: Fixed<8>): boolean;
* }
* const contractAddress = Address.from('0xcef0c0fdcfe7838eff6ff104f9cdec2922297537');
* const contract = SmartContract.for<TransferContract>(contractAddress);
* const from = Address.from('ALfnhLg7rUyL6Jr98bzzoxz5J7m64fbR4s');
* const to = Address.from('AVf4UGKevVrMR1j3UkPsuoYKSC4ocoAkKx');
* contract.transfer(from, to, 10);
*
* @param hash `Address` of the smart contract
* @returns an object representing the underlying smart contract
* Used to enforce that a `Transaction` with native `Asset`s is only ever processed once by an appropriate `@receive` or `@send` method.
*/
readonly for: <T>(hash: T extends IsValidSmartContract<T> ? Address : never) => T;
}
export const SmartContract: SmartContractConstructor;
/**
* Additonal properties available for linked smart contracts.
*/
export interface LinkedSmartContract {
protected readonly processedTransactions: SetStorage<Hash256>;
/**
* `Address` of the `LinkedSmartContract`.
* Stores `Transaction` hashes that can be refunded.
*/
readonly address: Address;
protected readonly allowedRefunds: SetStorage<Hash256>;
/**
* Property primarily used internally to validate that the smart contract is deployed only once.
*/
protected readonly deployed: true;
/**
* Method automatically added for refunding native `Asset`s.
*/
readonly refundAssets: (transactionHash: Hash256) => boolean;
static readonly for: <T>(hash: T extends IsValidSmartContract<T> ? Address : never) => T;
}
export interface LinkedSmartContractConstructor {

@@ -1004,3 +1161,3 @@ /**

*
* `T` is checked for validity and `getLinkedSmartContract` will report an error during compilation if the interface is invalid.
* `T` is checked for validity and `LinkedSmartContract.for` will report an error during compilation if the interface is invalid.
*

@@ -1017,3 +1174,4 @@ * @example

*/
readonly for: <T extends SmartContract>() => T extends IsValidSmartContract<T> ? T & LinkedSmartContract : never;
readonly for: <T extends SmartContract>() => T extends IsValidSmartContract<T> ? T : never;
readonly [OpaqueTagSymbol0]: unique symbol;
}

@@ -1023,8 +1181,28 @@ export const LinkedSmartContract: LinkedSmartContractConstructor;

/**
* Marks a `SmartContract` method to be verified before execution.
* Marks a `SmartContract` method that verifies `Asset` transfers from the `SmartContract`.
*
* Method must return a boolean indicating whether the `SmartContract` wishes to send the transferred `Asset`s.
*
* May be used in combination with `@receive`
*/
export function verify(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
export function send(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* Marks a `SmartContract` method as constant.
* Marks a `SmartContract` method that verifies receiving `Asset`s to the `SmartContract`.
*
* Method must return a boolean indicating whether the `SmartContract` wishes to receive the transferred `Asset`s.
*
* May be used in combination with `@send`.
*/
export function receive(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* Marks a `SmartContract` method that verifies GAS claims from the `SmartContract`.
*
* Method must return a boolean indicating whether the `SmartContract` wishes to allow GAS to be claimed.
*
* May optionally take the `ClaimTransaction` this `SmartContract` is executed in as the last argument. Accessing `Blockchain.currentTransaction` will result in an error.
*/
export function claim(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* Marks a `SmartContract` method as not modifying storage.
*/
export function constant(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc