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-preview.0 to 1.0.0-preview.1

2

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

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

@@ -49,2 +49,98 @@ // tslint:disable

interface CallableFunction extends Function {
/**
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
* @param thisArg The object to be used as the this object.
* @param args An array of argument values to be passed to the function.
*/
apply<T, R>(this: (this: T) => R, thisArg: T): R;
apply<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R;
/**
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
* @param thisArg The object to be used as the this object.
* @param args Argument values to be passed to the function.
*/
call<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A): R;
/**
* For a given function, creates a bound function that has the same body as the original function.
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
* @param thisArg The object to be used as the this object.
* @param args Arguments to bind to the parameters of the function.
*/
bind<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T): (...args: A) => R;
bind<T, A0, A extends any[], R>(this: (this: T, arg0: A0, ...args: A) => R, thisArg: T, arg0: A0): (...args: A) => R;
bind<T, A0, A1, A extends any[], R>(
this: (this: T, arg0: A0, arg1: A1, ...args: A) => R,
thisArg: T,
arg0: A0,
arg1: A1,
): (...args: A) => R;
bind<T, A0, A1, A2, A extends any[], R>(
this: (this: T, arg0: A0, arg1: A1, arg2: A2, ...args: A) => R,
thisArg: T,
arg0: A0,
arg1: A1,
arg2: A2,
): (...args: A) => R;
bind<T, A0, A1, A2, A3, A extends any[], R>(
this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R,
thisArg: T,
arg0: A0,
arg1: A1,
arg2: A2,
arg3: A3,
): (...args: A) => R;
bind<T, AX, R>(this: (this: T, ...args: AX[]) => R, thisArg: T, ...args: AX[]): (...args: AX[]) => R;
}
interface NewableFunction extends Function {
/**
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
* @param thisArg The object to be used as the this object.
* @param args An array of argument values to be passed to the function.
*/
apply<T>(this: new () => T, thisArg: T): void;
apply<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, args: A): void;
/**
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
* @param thisArg The object to be used as the this object.
* @param args Argument values to be passed to the function.
*/
call<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, ...args: A): void;
/**
* For a given function, creates a bound function that has the same body as the original function.
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
* @param thisArg The object to be used as the this object.
* @param args Arguments to bind to the parameters of the function.
*/
bind<A extends any[], R>(this: new (...args: A) => R, thisArg: any): new (...args: A) => R;
bind<A0, A extends any[], R>(this: new (arg0: A0, ...args: A) => R, thisArg: any, arg0: A0): new (...args: A) => R;
bind<A0, A1, A extends any[], R>(
this: new (arg0: A0, arg1: A1, ...args: A) => R,
thisArg: any,
arg0: A0,
arg1: A1,
): new (...args: A) => R;
bind<A0, A1, A2, A extends any[], R>(
this: new (arg0: A0, arg1: A1, arg2: A2, ...args: A) => R,
thisArg: any,
arg0: A0,
arg1: A1,
arg2: A2,
): new (...args: A) => R;
bind<A0, A1, A2, A3, A extends any[], R>(
this: new (arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R,
thisArg: any,
arg0: A0,
arg1: A1,
arg2: A2,
arg3: A3,
): new (...args: A) => R;
bind<AX, R>(this: new (...args: AX[]) => R, thisArg: any, ...args: AX[]): new (...args: AX[]) => R;
}
interface IArguments {

@@ -417,1 +513,5 @@ readonly [one0]: unique symbol;

interface TemplateStringsArray extends Array<string> {}
type Constructor<T> = new (...args: any[]) => T;
type Parameters<T extends Function> = T extends (...args: infer U) => any ? U : never;
type ReturnType<T extends Function> = T extends (...args: any[]) => infer R ? R : never;

@@ -746,5 +746,8 @@ // tslint:disable

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 interface SerializableValueArray extends ReadonlyArray<SerializableValue> {}
export interface SerializableValueMap extends ReadonlyMap<SerializableKeySingle, SerializableValue> {}
export interface SerializableValueSet extends ReadonlySet<SerializableValue> {}
export interface SerializableValueObject {
readonly [key: string]: SerializableValue;
}
export type SerializableValue =

@@ -759,3 +762,4 @@ | undefined

| SerializableValueMap
| SerializableValueSet;
| SerializableValueSet
| SerializableValueObject;

@@ -1067,3 +1071,48 @@ /**

export function declareEvent(name: string): void;
export function declareEvent<A0>(name: string, arg0Name: string): void;
export function declareEvent<A0, A1>(name: string, arg0Name: string, arg1Name: string): void;
export function declareEvent<A0, A1, A2>(name: string, arg0Name: string, arg1Name: string, arg2Name: string): void;
export function declareEvent<A0, A1, A2, A3>(
name: string,
arg0Name: string,
arg1Name: string,
arg2Name: string,
arg3Name: string,
): void;
export function declareEvent<A0, A1, A2, A3, A4>(
name: string,
arg0Name: string,
arg1Name: string,
arg2Name: string,
arg3Name: string,
arg4Name: string,
): void;
/**
* Creates an event notifier for `SmartContract` notifications.
*
* Must be explicitly typed and contain string literals for the event name and argument names.
*
* @example
*
* const notifyTransfer = declareEvent<Address, Address, Fixed<8>>('transfer', 'from', 'to', 'amount');
*
* const from = Address.from('ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW');
* const to = Address.from('AVf4UGKevVrMR1j3UkPsuoYKSC4ocoAkKx');
* notifyTransfer(from, to, 200);
*
* @param name Event name
* @param argName Event argument name
*/
export function declareEvent<A0, A1, A2, A3, A4, A5>(
name: string,
arg0Name: string,
arg1Name: string,
arg2Name: string,
arg3Name: string,
arg4Name: string,
arg5Name: string,
): void;
/**
* Object with string literals for the contract properties to be used in deployment.

@@ -1094,2 +1143,4 @@ */

readonly asArrayNullable: () => Array<ForwardValue> | undefined;
readonly asMap: () => Map<ForwardValue, ForwardValue>;
readonly asMapNullable: () => Map<ForwardValue, ForwardValue> | undefined;
readonly [OpaqueTagSymbol0]: unique symbol;

@@ -1102,10 +1153,17 @@ }

interface ForwardedValueTag<T extends SmartContractValue> {}
interface ForwardedValueTag<T extends SmartContractArg> {}
/**
* Marks a parameter or return type of a public `SmartContract` method as expecting a forwarded value.
*/
export type ForwardedValue<T extends SmartContractValue> = T | (T & ForwardedValueTag<T>);
export type ForwardedValue<T extends SmartContractArg> = T | (T & ForwardedValueTag<T>);
interface SmartContractValueArray extends Array<SmartContractValue> {}
interface SmartContractValueReadonlyArray extends ReadonlyArray<SmartContractValue> {}
interface SmartContractValueReadonlyArray<Value extends SmartContractValue = any> extends ReadonlyArray<Value> {}
interface SmartContractValueMap<Key extends SmartContractValue = any, Value extends SmartContractValue = any>
extends Map<Key, Value> {}
interface SmartContractValueReadonlyMap<Key extends SmartContractValue = any, Value extends SmartContractValue = any>
extends ReadonlyMap<Key, Value> {}
interface SmartContractValueObject {
readonly [key: string]: SmartContractValue;
}
type SmartContractValue =

@@ -1124,6 +1182,7 @@ | void

| SmartContractValueArray
| SmartContractValueReadonlyArray;
| SmartContractValueReadonlyArray
| SmartContractValueMap
| SmartContractValueReadonlyMap
| SmartContractValueObject;
type SmartContractArg = SmartContractValue | ForwardValue;
type Parameters<T extends Function> = T extends (...args: infer U) => any ? U : never;
type ReturnType<T extends Function> = T extends (...args: any[]) => infer R ? R : never;
type IsValidSmartContract<T> = {

@@ -1138,7 +1197,7 @@ [K in keyof T]: T[K] extends Function

*/
export abstract class SmartContract {
export class SmartContract {
/**
* Properties used for deployment of the `SmartContract`
*/
public abstract readonly properties: ContractProperties;
public readonly properties: ContractProperties;
/**

@@ -1149,11 +1208,15 @@ * `Address` of the `SmartContract`.

/**
* Stores `Transaction` hashes that have been processed by a method marked with `@receive` or `@send`.
* Stores `Transaction` hashes that have been processed by a method marked with `@receive`, `@send`, or `@sendUnsafe`.
*
* Used to enforce that a `Transaction` with native `Asset`s is only ever processed once by an appropriate `@receive` or `@send` method.
* Used to enforce that a `Transaction` with native `Asset`s is only ever processed once by an appropriate `@receive`, `@send`, or `@sendUnsafe` method.
*
* Unprocessed transactions that sent assets to the smart contract can be refunded by using `refundAssets`.
*/
protected readonly processedTransactions: SetStorage<Hash256>;
/**
* Stores `Transaction` hashes that can be refunded.
* Stores `Transaction` hashes that have been claimed by an address with a method marked with `@send`.
*
* The first contract output of a claimed transaction may be sent to the receiver by using `completeSend`.
*/
protected readonly allowedRefunds: SetStorage<Hash256>;
protected readonly claimedTransactions: MapStorage<Hash256, Address>;
/**

@@ -1164,6 +1227,44 @@ * Property primarily used internally to validate that the smart contract is deployed only once.

/**
* Override to validate a contract upgrade invocation. Returns `false` by default. Return `true` to indicate the upgrade may proceed.
*
* @example
*
* export class Contract extends SmartContract {
* public constructor(private readonly owner = Deploy.senderAddress) {
* super();
* }
*
* protected approveUpgrade(): boolean {
* return Address.isCaller(this.owner);
* }
* }
*/
protected approveUpgrade(): boolean;
/**
* Permanently deletes the contract.
*/
protected readonly destroy: () => void;
/**
* 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;
public readonly refundAssets: () => boolean;
/**
* Method automatically added for sending native `Asset`s that have been claimed by a `@send` method.
*/
public readonly completeSend: () => boolean;
/**
* Used internally by client APIs to upgrade the contract. Control whether an invocation is allowed to upgrade the contract by overriding `approveUpgrade`.
*/
public readonly upgrade: (
script: Buffer,
parameterList: Buffer,
returnType: number,
properties: number,
contractName: string,
codeVersion: string,
author: string,
email: string,
description: string,
) => boolean;
public static readonly for: <T>(address: T extends IsValidSmartContract<T> ? Address : never) => T;
}

@@ -1204,8 +1305,33 @@

*
* Method must return a boolean indicating whether the `SmartContract` wishes to send the transferred `Asset`s.
* Method must return a boolean indicating whether the `SmartContract` wishes to approve sending the transferred `Asset`s.
*
* May be used in combination with `@receive`
* Method can take the receiving address, asset and amount as the final arguments.
*
* @example
*
* export class Contract extends SmartContract {
* @send
* public withdraw(arg0: Address, arg1: Fixed<8>, receiver: Address, asset: Hash256, amount: Fixed<8>): boolean {
* // Don't allow sending anything but NEO
* if (!asset.equals(Hash256.NEO)) {
* return false;
* }
* // Do some additional checks on the receiver and amount being sent and other arguments.
* return true;
* }
* }
*
*/
export function send(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* Marks a `SmartContract` method that verifies `Asset` transfers from the `SmartContract`.
*
* Method must return a boolean indicating whether the `SmartContract` wishes to approve sending the transferred `Asset`s.
*
* Note that unlike `@send`, `@sendUnsafe` does not use a two-phase send. Smart contract authors must implement their own logic for safely sending assets from the contract.
*
* May be used in combination with `@receive`.
*/
export function sendUnsafe(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* Marks a `SmartContract` method that verifies receiving `Asset`s to the `SmartContract`.

@@ -1215,3 +1341,3 @@ *

*
* May be used in combination with `@send`.
* May be used in combination with `@sendUnsafe`.
*/

@@ -1218,0 +1344,0 @@ export function receive(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;

{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"noLib": true,
"typeRoots": [],
"pretty": true,
"noEmit": true,
"declaration": false,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": false,
"experimentalDecorators": true,
"alwaysStrict": true,

@@ -20,0 +15,0 @@ "strict": true,

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