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

Adding errors for state rent change #270

Merged
merged 3 commits into from
Mar 27, 2020
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ yarn test
```

Tests use sample contract from `near-hello` npm package, see https://github.com/nearprotocol/near-hello

## Update error messages

Follow next steps:

1. [Change hash for the commit with errors in the nearcore](https://github.com/nearprotocol/nearlib/blob/master/gen_error_types.js#L7-L9)
2. Generate new types for errors: `node gen_error_types.js`
3. `yarn lint --fix` fix any issues with linter.
4. `yarn build` to update `lib/**.js` files

2 changes: 1 addition & 1 deletion gen_error_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
} = require('ts-morph');

const ERROR_SCHEMA_URL =
'https://raw.githubusercontent.com/nearprotocol/nearcore/2b12956e3787fa876e0ba959559e67edb73635c5/chain/jsonrpc/res/rpc_errors_schema.json';
'https://raw.githubusercontent.com/nearprotocol/nearcore/84a805e0fe4d507d03d6525f68fec99b7d1d6048/chain/jsonrpc/res/rpc_errors_schema.json';
const TARGET_DIR = process.argv[2] || process.cwd() + '/src.ts/generated';
const TARGET_TS_FILE_PATH = TARGET_DIR + '/rpc_error_types.ts';
const TARGET_SCHEMA_FILE_PATH = TARGET_DIR + '/rpc_error_schema.json';
Expand Down
41 changes: 37 additions & 4 deletions lib/generated/rpc_error_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"NumberPromisesExceeded",
"NumberInputDataDependenciesExceeded",
"ReturnedValueLengthExceeded",
"ContractSizeExceeded"
"ContractSizeExceeded",
"Deprecated"
],
"props": {}
},
Expand Down Expand Up @@ -377,10 +378,11 @@
"DeleteKeyDoesNotExist",
"AddKeyAlreadyExists",
"DeleteAccountStaking",
"DeleteAccountHasRent",
"RentUnpaid",
"DeleteAccountHasEnoughBalance",
"LackBalanceForState",
"TriesToUnstake",
"TriesToStake",
"UnsuitableStakingKey",
"FunctionCallError",
"NewReceiptValidationError"
],
Expand Down Expand Up @@ -523,7 +525,7 @@
"InvalidReceiverId",
"InvalidSignature",
"NotEnoughBalance",
"RentUnpaid",
"LackBalanceForState",
"CostOverflow",
"InvalidChain",
"Expired",
Expand Down Expand Up @@ -628,6 +630,37 @@
"name": "Timeout",
"subtypes": [],
"props": {}
},
"UnsuitableStakingKey": {
"name": "UnsuitableStakingKey",
"subtypes": [],
"props": {
"public_key": ""
}
},
"LackBalanceForState": {
"name": "LackBalanceForState",
"subtypes": [],
"props": {
"amount": "",
"signer_id": "",
"account_id": ""
}
},
"DeleteAccountHasEnoughBalance": {
"name": "DeleteAccountHasEnoughBalance",
"subtypes": [],
"props": {
"account_id": "",
"balance": ""
}
},
"Deprecated": {
"name": "Deprecated",
"subtypes": [],
"props": {
"method_name": ""
}
}
}
}
21 changes: 18 additions & 3 deletions lib/generated/rpc_error_types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions lib/generated/rpc_error_types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions src.ts/generated/rpc_error_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"NumberPromisesExceeded",
"NumberInputDataDependenciesExceeded",
"ReturnedValueLengthExceeded",
"ContractSizeExceeded"
"ContractSizeExceeded",
"Deprecated"
],
"props": {}
},
Expand Down Expand Up @@ -377,10 +378,11 @@
"DeleteKeyDoesNotExist",
"AddKeyAlreadyExists",
"DeleteAccountStaking",
"DeleteAccountHasRent",
"RentUnpaid",
"DeleteAccountHasEnoughBalance",
"LackBalanceForState",
"TriesToUnstake",
"TriesToStake",
"UnsuitableStakingKey",
"FunctionCallError",
"NewReceiptValidationError"
],
Expand Down Expand Up @@ -523,7 +525,7 @@
"InvalidReceiverId",
"InvalidSignature",
"NotEnoughBalance",
"RentUnpaid",
"LackBalanceForState",
"CostOverflow",
"InvalidChain",
"Expired",
Expand Down Expand Up @@ -628,6 +630,37 @@
"name": "Timeout",
"subtypes": [],
"props": {}
},
"UnsuitableStakingKey": {
"name": "UnsuitableStakingKey",
"subtypes": [],
"props": {
"public_key": ""
}
},
"LackBalanceForState": {
"name": "LackBalanceForState",
"subtypes": [],
"props": {
"amount": "",
"signer_id": "",
"account_id": ""
}
},
"DeleteAccountHasEnoughBalance": {
"name": "DeleteAccountHasEnoughBalance",
"subtypes": [],
"props": {
"account_id": "",
"balance": ""
}
},
"Deprecated": {
"name": "Deprecated",
"subtypes": [],
"props": {
"method_name": ""
}
}
}
}
23 changes: 21 additions & 2 deletions src.ts/generated/rpc_error_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class CreateAccountNotAllowed extends ActionError {
public predecessor_id;
}

export class DeleteAccountHasRent extends ActionError {
export class DeleteAccountHasRent extends TypedError {
public account_id;
public balance;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ export class ReceiverMismatch extends InvalidAccessKeyError {
public tx_receiver;
}

export class RentUnpaid extends ActionError {
export class RentUnpaid extends TypedError {
public account_id;
public amount;
}
Expand Down Expand Up @@ -326,3 +326,22 @@ export class Closed extends ServerError {

export class Timeout extends ServerError {
}

export class UnsuitableStakingKey extends ActionError {
public public_key;
}

export class LackBalanceForState extends ActionError {
public amount;
public signer_id;
public account_id;
}

export class DeleteAccountHasEnoughBalance extends ActionError {
public account_id;
public balance;
}

export class Deprecated extends HostError {
public method_name;
}
4 changes: 3 additions & 1 deletion src.ts/res/error_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"InvalidPublicKey": "VM Logic provided an invalid public key",
"ActorNoPermission": "Actor {{actor_id}} doesn't have permission to account {{account_id}} to complete the action",
"RentUnpaid": "The account {{account_id}} wouldn't have enough balance to pay required rent {{amount}}",
"LackBalanceForState": "The account {{account_id}} wouldn't have enough balance to cover storage, required to have {{amount}}",
"ReceiverMismatch": "Wrong AccessKey used for transaction: transaction is sent to receiver_id={{tx_receiver}}, but is signed with function call access key that restricted to only use with receiver_id={{ak_receiver}}. Either change receiver_id in your transaction or switch to use a FullAccessKey.",
"CostOverflow": "Transaction gas or balance cost is too high",
"InvalidSignature": "Transaction is not signed with the given public key",
Expand All @@ -58,8 +59,9 @@
"AccountDoesNotExist": "Can't complete the action because account {{account_id}} doesn't exist",
"MethodNameMismatch": "Transaction method name {{method_name}} isn't allowed by the access key",
"DeleteAccountHasRent": "Account {{account_id}} can't be deleted. It has {balance{}}, which is enough to cover the rent",
"DeleteAccountHasEnoughBalance": "Account {{account_id}} can't be deleted. It has {balance{}}, which is enough to cover it's storage",
"InvalidReceiver": "Invalid receiver account ID {{receiver_id}} according to requirements",
"DeleteKeyDoesNotExist": "Account {{account_id}} tries to remove an access key that doesn't exist",
"Timeout": "Timeout exceeded",
"Closed": "Connection closed"
}
}