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

Preview4 blockchain changes #2283

Closed
Closed
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
2 changes: 2 additions & 0 deletions packages/neo-one-client-common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const isWildcard = (input: unknown): input is Wildcard => input === '*';

const NEGATIVE_SATOSHI_FIXED8 = new BN(-1);
const TEN_FIXED8 = fixed8FromDecimal(10);
const TWENTY_FIXED8 = fixed8FromDecimal(20);
const ONE_HUNDRED_FIXED8 = fixed8FromDecimal(100);
const FOUR_HUNDRED_FIXED8 = fixed8FromDecimal(400);
const FIVE_HUNDRED_FIXED8 = fixed8FromDecimal(500);
Expand Down Expand Up @@ -249,6 +250,7 @@ export const common = {
MAX_UINT256,
NEGATIVE_SATOSHI_FIXED8,
TEN_FIXED8,
TWENTY_FIXED8,
ONE_HUNDRED_FIXED8,
FOUR_HUNDRED_FIXED8,
FIVE_HUNDRED_FIXED8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface FeelessTransactionModelAdd<

export const MAX_TRANSACTION_ATTRIBUTES = 16;
export const MAX_TRANSACTION_SIZE = 102400;
export const MAX_VALID_UNTIL_BLOCK_INCREMENT = 2102400;
export const MAX_VALID_UNTIL_BLOCK_INCREMENT = 5760; // 24 hours
export const DEFAULT_VERSION = 0;

export class FeelessTransactionModel<
Expand Down
5 changes: 4 additions & 1 deletion packages/neo-one-client-common/src/models/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { InvalidFormatError } from '../common';

export enum TriggerType {
OnPersist = 0x01,
PostPersist = 0x02,
Verification = 0x20,
System = 0x01,
Application = 0x40,
System = OnPersist | PostPersist,
All = OnPersist | PostPersist | Verification | Application,
}

export type TriggerTypeJSON = keyof typeof TriggerType;
Expand Down
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
13 changes: 7 additions & 6 deletions packages/neo-one-client-common/src/models/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,17 @@ export enum SysCall {
'System.Blockchain.GetTransaction' = 'System.Blockchain.GetTransaction',
'System.Blockchain.GetTransactionHeight' = 'System.Blockchain.GetTransactionHeight',
'System.Blockchain.GetTransactionFromBlock' = 'System.Blockchain.GetTransactionFromBlock',
'System.Blockchain.GetContract' = 'System.Blockchain.GetContract',
'System.Callback.Create' = 'System.Callback.Create',
'System.Callback.CreateFromMethod' = 'System.Callback.CreateFromMethod',
'System.Callback.CreateFromSyscall' = 'System.Callback.CreateFromSyscall',
'System.Callback.Invoke' = 'System.Callback.Invoke',
'System.Contract.Create' = 'System.Contract.Create',
'System.Contract.Update' = 'System.Contract.Update',
'System.Contract.Destroy' = 'System.Contract.Destroy',
'System.Contract.Call' = 'System.Contract.Call',
'System.Contract.CallEx' = 'System.Contract.CallEx',
'System.Contract.CallNative' = 'System.Contract.CallNative',
'System.Contract.IsStandard' = 'System.Contract.IsStandard',
'System.Contract.GetCallFlags' = 'System.Contract.GetCallFlags',
'System.Contract.NativeOnPersist' = 'System.Contract.NativeOnPersist',
'System.Contract.NativePostPersist' = 'System.Contract.NativePostPersist',
'System.Contract.CreateStandardAccount' = 'System.Contract.CreateStandardAccount',
'Neo.Crypto.RIPEMD160' = 'Neo.Crypto.RIPEMD160',
'Neo.Crypto.SHA256' = 'Neo.Crypto.SHA256',
Expand All @@ -254,8 +253,6 @@ export enum SysCall {
'System.Iterator.Concat' = 'System.Iterator.Concat',
'System.Json.Serialize' = 'System.Json.Serialize',
'System.Json.Deserialize' = 'System.Json.Deserialize',
'Neo.Native.Deploy' = 'Neo.Native.Deploy',
'Neo.Native.Call' = 'Neo.Native.Call',
'System.Runtime.Platform' = 'System.Runtime.Platform',
'System.Runtime.GetTrigger' = 'System.Runtime.GetTrigger',
'System.Runtime.GetTime' = 'System.Runtime.GetTime',
Expand All @@ -277,6 +274,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
Loading