Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sc): Update SC / Compiler changes to match preview4 changes #2277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/neo-one-client-common/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export interface ContractMethodDescriptorJSON {
readonly parameters: readonly ContractParameterDefinitionJSON[];
readonly offset: number;
readonly returntype: ContractParameterTypeJSON;
readonly safe: boolean;
}

export interface ContractEventDescriptorJSON {
Expand Down Expand Up @@ -377,11 +378,6 @@ export interface ContractManifestJSON {
readonly groups: readonly ContractGroupJSON[];
readonly permissions: readonly ContractPermissionJSON[];
readonly trusts: WildcardContainerJSON;
readonly safemethods: WildcardContainerJSON;
readonly features: {
readonly storage: boolean;
readonly payable: boolean;
};
readonly supportedstandards: readonly string[];
readonly extra?: JSONObject;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/neo-one-client-common/src/models/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ export enum SysCall {
'System.Storage.Put' = 'System.Storage.Put',
'System.Storage.PutEx' = 'System.Storage.PutEx',
'System.Storage.Delete' = 'System.Storage.Delete',
'System.Binary.Base58Encode' = 'System.Binary.Base58Encode',
'System.Binary.Base58Decode' = 'System.Binary.Base58Decode',
'System.Binary.Itoa' = 'System.Binary.Itoa',
'System.Binary.Atoi' = 'System.Binary.Atoi',
}

export type SysCallName = keyof typeof SysCall;
Expand Down
16 changes: 8 additions & 8 deletions packages/neo-one-client-common/src/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const opCodePrices: Record<Op, BigNumber | undefined> = {
[Op.REVERSE4]: new BigNumber(60),
[Op.REVERSEN]: new BigNumber(400),
[Op.INITSSLOT]: new BigNumber(400),
[Op.INITSLOT]: new BigNumber(800),
[Op.INITSLOT]: new BigNumber(1600),
[Op.LDSFLD0]: new BigNumber(60),
[Op.LDSFLD1]: new BigNumber(60),
[Op.LDSFLD2]: new BigNumber(60),
Expand Down Expand Up @@ -140,8 +140,8 @@ const opCodePrices: Record<Op, BigNumber | undefined> = {
[Op.AND]: new BigNumber(200),
[Op.OR]: new BigNumber(200),
[Op.XOR]: new BigNumber(200),
[Op.EQUAL]: new BigNumber(200),
[Op.NOTEQUAL]: new BigNumber(200),
[Op.EQUAL]: new BigNumber(1000),
[Op.NOTEQUAL]: new BigNumber(1000),
[Op.SIGN]: new BigNumber(100),
[Op.ABS]: new BigNumber(100),
[Op.NEGATE]: new BigNumber(100),
Expand All @@ -167,8 +167,8 @@ const opCodePrices: Record<Op, BigNumber | undefined> = {
[Op.MIN]: new BigNumber(200),
[Op.MAX]: new BigNumber(200),
[Op.WITHIN]: new BigNumber(200),
[Op.PACK]: new BigNumber(7000),
[Op.UNPACK]: new BigNumber(7000),
[Op.PACK]: new BigNumber(15000),
[Op.UNPACK]: new BigNumber(15000),
[Op.NEWARRAY0]: new BigNumber(400),
[Op.NEWARRAY]: new BigNumber(15000),
[Op.NEWARRAY_T]: new BigNumber(15000),
Expand All @@ -178,11 +178,11 @@ const opCodePrices: Record<Op, BigNumber | undefined> = {
[Op.SIZE]: new BigNumber(150),
[Op.HASKEY]: new BigNumber(270000),
[Op.KEYS]: new BigNumber(500),
[Op.VALUES]: new BigNumber(7000),
[Op.VALUES]: new BigNumber(270000),
[Op.PICKITEM]: new BigNumber(270000),
[Op.APPEND]: new BigNumber(15000),
[Op.APPEND]: new BigNumber(270000),
[Op.SETITEM]: new BigNumber(270000),
[Op.REVERSEITEMS]: new BigNumber(500),
[Op.REVERSEITEMS]: new BigNumber(270000),
[Op.REMOVE]: new BigNumber(500),
[Op.CLEARITEMS]: new BigNumber(400),
[Op.ISNULL]: new BigNumber(60),
Expand Down
78 changes: 8 additions & 70 deletions packages/neo-one-client-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,10 @@ export interface ContractMethodDescriptorClient {
* TODO: describe
*/
readonly returnType: ABIReturn;
/**
* flags this as a safe method callable by any source.
*/
readonly safe: boolean;
/**
* TODO: fill out description here
*/
Expand Down Expand Up @@ -1467,28 +1471,6 @@ export interface ContractGroup {
readonly signature: BufferString;
}

/**
* Flag which determines which features are available to a contract.
*/
export enum ContractFeatures {
/**
* Contract does not use any available features.
*/
NoProperty = 0x00,
/**
* Contract modifies blockchain storage.
*/
HasStorage = 0x01,
/**
* Contract can receive native assets.
*/
Payable = 0x04,
/**
* Contract modifies blockchain storage and can receive native assets.
*/
HasStoragePayable = 0x05,
}

export type WildcardContainer<T> = readonly T[] | Wildcard;

/**
Expand All @@ -1514,8 +1496,8 @@ export interface ContractPermission {
}

/**
* A manifest explicitly declares the features and permissions a Contract will use. Once deployed,
* it will be limited by its declared list of features and permissions. `ContractManifestClient`
* A manifest explicitly declares the permissions a Contract will use. Once deployed,
* it will be limited by its declared list of permissions. `ContractManifestClient`
* specifically contains extra contract information for use in the NEO•ONE Client
*/
export interface ContractManifestClient {
Expand All @@ -1527,13 +1509,6 @@ export interface ContractManifestClient {
* Set of mutually trusted contracts.
*/
readonly groups: readonly ContractGroup[];
/**
* The features field describes what features are available for the contract.
*/
readonly features: {
readonly storage: boolean;
readonly payable: boolean;
};
/**
* The Neo Enhancement Proposals (NEPs) and other standards that this smart contract supports.
*/
Expand All @@ -1552,46 +1527,21 @@ export interface ContractManifestClient {
* The trusts field is an array containing a set of contract hashes or group of public keys.
*/
readonly trusts: WildcardContainer<UInt160Hex>;
/**
* The safeMethods field is an array containing a set of safe methods.
*/
readonly safeMethods: WildcardContainer<string>;
/**
* Custom user-defined JSON object.
*/
readonly extra?: JSONObject;
/**
* True if the `Contract` modified blockchain storage.
*/
readonly hasStorage: boolean;
/**
* True if the `Contract` can receive native assets.
*/
readonly payable: boolean;
}

/**
* A manifest explicitly declares the features and permissions a Contract will use. Once deployed,
* it will be limited by its declared list of features and permissions.
* A manifest explicitly declares the permissions a Contract will use. Once deployed,
* it will be limited by its declared list of permissions.
*/
export interface ContractManifest {
/**
* Set of mutually trusted contracts.
*/
readonly groups: readonly ContractGroup[];
/**
* The features field describes what features are available for the contract.
*/
readonly features: {
/**
* True if the `Contract` modified blockchain storage.
*/
readonly storage: boolean;
/**
* True if the `Contract` can receive assets.
*/
readonly payable: boolean;
};
/**
* The Neo Enhancement Proposals (NEPs) and other standards that this smart contract supports.
*/
Expand All @@ -1609,22 +1559,10 @@ export interface ContractManifest {
* The trusts field is an array containing a set of contract hashes or group of public keys.
*/
readonly trusts: WildcardContainer<UInt160Hex>;
/**
* The safeMethods field is an array containing a set of safe methods.
*/
readonly safeMethods: WildcardContainer<string>;
/**
* Custom user-defined JSON object.
*/
readonly extra?: JSONObject;
/**
* True if the `Contract` modified blockchain storage.
*/
readonly hasStorage: boolean;
/**
* True if the `Contract` can receive assets.
*/
readonly payable: boolean;
}

declare const OpaqueTagSymbol: unique symbol;
Expand Down
10 changes: 1 addition & 9 deletions packages/neo-one-client-core/src/__data__/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const createContractABIJSON = (options: Partial<ContractABIJSON> = {}): Contract
});

const createManifestJSON = (options: Partial<ContractManifestJSON> = {}): ContractManifestJSON => {
const { abi, features, ...optionsIn } = options;
const { abi, ...optionsIn } = options;

return {
hash: keys[0].scriptHashString,
Expand All @@ -102,12 +102,6 @@ const createManifestJSON = (options: Partial<ContractManifestJSON> = {}): Contra
groups: [], // TODO
permissions: [], // TODO
trusts: '*',
safeMethods: '*',
features: {
storage: true,
payable: true,
...features,
},
supportedStandards: [], // TODO
...optionsIn,
};
Expand All @@ -120,8 +114,6 @@ const createContractJSON = (options: Partial<ContractJSON> = {}): ContractJSON =
id: 0,
script: data.buffers.b,
manifest: createManifestJSON(manifest),
hasStorage: true,
payable: true,
...optionsIn,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const verifyManifest = (manifest: ContractManifest, manifestJSON: ContractManife
expect(manifest.hash).toEqual(scriptHashToAddress(manifestJSON.hash));
// TODO: hashHex
expect(manifest.trusts).toEqual(manifestJSON.trusts);
expect(manifest.safeMethods).toEqual(manifestJSON.safeMethods);
expect(manifest.features).toEqual(manifestJSON.features);
expect(manifest.supportedStandards).toEqual(manifestJSON.supportedStandards);
expect(manifest.extra).toEqual(manifestJSON.extra);
verifyAbi(manifest.abi, manifestJSON.abi);
Expand All @@ -114,8 +112,6 @@ const verifyManifest = (manifest: ContractManifest, manifestJSON: ContractManife
const verifyContract = (contract: Contract, contractJSON: ContractJSON, returnType = 'Buffer') => {
expect(contract.id).toEqual(contractJSON.id);
expect(contract.script).toEqual(contractJSON.script);
expect(contract.hasStorage).toEqual(contractJSON.hasStorage);
expect(contract.payable).toEqual(contractJSON.payable);
verifyManifest(contract.manifest, contractJSON.manifest);
};

Expand Down
14 changes: 0 additions & 14 deletions packages/neo-one-client-core/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,6 @@ export const assertContractManifestClient = (name: string, value?: unknown): Con
groups: assertProperty(value, 'ContractManifest', 'groups', assertArray).map((group) =>
assertContractGroup('ContractManifest.groups', group),
),
features: {
storage: assertProperty(value, 'ContractManifest', 'hasStorage', assertBoolean),
payable: assertProperty(value, 'ContractManifest', 'payable', assertBoolean),
},
supportedStandards: assertProperty(value, 'ContractManifest', 'supportedStandards', assertArray).map((std) =>
assertString('ContractManifest.supportedStandards', std),
),
Expand All @@ -801,10 +797,7 @@ export const assertContractManifestClient = (name: string, value?: unknown): Con
assertContractPermission('ContractManifest.permissions', permission),
),
trusts: assertWildcardContainerProperty(value, 'ContractManifest', 'trusts', assertUInt160Hex),
safeMethods: assertWildcardContainerProperty(value, 'ContractManifest', 'safeMethods', assertString),
extra: assertProperty(value, 'ContractManifest', 'extra', assertNullableJSON),
hasStorage: assertProperty(value, 'ContractManifest', 'hasStorage', assertBoolean),
payable: assertProperty(value, 'ContractManifest', 'payable', assertBoolean),
};
};

Expand All @@ -817,10 +810,6 @@ export const assertContractManifest = (name: string, value?: unknown): ContractM
groups: assertProperty(value, 'ContractManifest', 'groups', assertArray).map((group) =>
assertContractGroup('ContractManifest.groups', group),
),
features: {
storage: assertProperty(value, 'ContractManifest', 'hasStorage', assertBoolean),
payable: assertProperty(value, 'ContractManifest', 'payable', assertBoolean),
},
supportedStandards: assertProperty(value, 'ContractManifest', 'supportedStandards', assertArray).map((std) =>
assertString('ContractManifest.supportedStandards', std),
),
Expand All @@ -829,10 +818,7 @@ export const assertContractManifest = (name: string, value?: unknown): ContractM
assertContractPermission('ContractManifest.permissions', permission),
),
trusts: assertWildcardContainerProperty(value, 'ContractManifest', 'trusts', assertUInt160Hex),
safeMethods: assertWildcardContainerProperty(value, 'ContractManifest', 'safeMethods', assertString),
extra: assertProperty(value, 'ContractManifest', 'extra', assertNullableJSON),
hasStorage: assertProperty(value, 'ContractManifest', 'hasStorage', assertBoolean),
payable: assertProperty(value, 'ContractManifest', 'payable', assertBoolean),
};
};

Expand Down
7 changes: 0 additions & 7 deletions packages/neo-one-client-core/src/nep5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,10 @@ export const abi = (decimals: number): ContractABIClient => ({
export const manifest = (decimals: number): ContractManifestClient => ({
hash: common.uInt160ToString(blankHash),
groups: [],
features: {
storage: true,
payable: true,
},
supportedStandards: [],
abi: abi(decimals),
permissions: [],
trusts: '*',
safeMethods: '*',
hasStorage: true,
payable: true,
});

export const getDecimals = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,11 @@ export class NEOONEDataProvider implements DeveloperProvider {
private convertContractManifest(manifest: ContractManifestJSON): ContractManifest {
return {
groups: manifest.groups.map(this.convertContractGroup),
features: {
storage: manifest.features.storage,
payable: manifest.features.payable,
},
supportedStandards: manifest.supportedstandards,
abi: this.convertContractABI(manifest.abi),
permissions: manifest.permissions.map(this.convertContractPermission),
trusts: manifest.trusts,
safeMethods: manifest.safemethods,
extra: manifest.extra,
hasStorage: manifest.features.storage,
payable: manifest.features.payable,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ export class LocalUserAccountProvider<TKeyStore extends KeyStore = KeyStore, TPr
crypto.addressToScriptHash({ addressVersion, address: from.address }),
crypto.addressToScriptHash({ addressVersion, address: transfer.to }),
transfer.amount.toNumber(),
undefined,
);
});

Expand Down
5 changes: 1 addition & 4 deletions packages/neo-one-client-full-common/src/__data__/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { constants } from '@neo-one/utils';
import {
ContractABIModel,
ContractEventDescriptorModel,
ContractFeaturesModel,
ContractGroupModel,
ContractManifestModel,
ContractMethodDescriptorModel,
Expand Down Expand Up @@ -112,13 +111,11 @@ export const contractPermissionModel = (

export const contractManifestModel = (
groups: readonly ContractGroupModel[] = [contractGroupModel()],
features: ContractFeaturesModel = ContractFeaturesModel.HasStoragePayable,
abi: ContractABIModel = contractAbiModel(),
permissions: readonly ContractPermissionModel[] = [contractPermissionModel('uint160', ['method1'])],
trusts: readonly UInt160[] = [common.bufferToUInt160(Buffer.alloc(20, 1))],
safeMethods: readonly string[] = ['method1', 'method2'],
supportedStandards: readonly string[] = [],
) => new ContractManifestModel({ groups, features, supportedStandards, abi, permissions, trusts, safeMethods });
) => new ContractManifestModel({ groups, supportedStandards, abi, permissions, trusts });

export const contractModel = (
id = 1,
Expand Down
Loading