Skip to content

Commit

Permalink
add transaction/status
Browse files Browse the repository at this point in the history
  • Loading branch information
renthog committed Dec 26, 2022
1 parent 0e51da7 commit 44fda53
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .yarn/versions/cb6afd9a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
undecided:
- root-workspace-0b6124
- "@tonic-foundation/config"
- "@tonic-foundation/storage"
- "@tonic-foundation/token"
- "@tonic-foundation/transaction"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"trailingComma": "es5",
"singleQuote": true
},
"version": "1.0.1",
"version": "1.0.2",
"packageManager": "[email protected]",
"devDependencies": {
"@tsconfig/recommended": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tonic-foundation/config",
"homepage": "https://github.com/tonic-foundation/near-utils-ts",
"repository": "tonic-foundation/near-utils-ts",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"files": [
"lib"
Expand Down
6 changes: 3 additions & 3 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tonic-foundation/storage",
"homepage": "https://github.com/tonic-foundation/near-utils-ts",
"repository": "tonic-foundation/near-utils-ts",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"files": [
"lib"
Expand All @@ -19,8 +19,8 @@
"typescript": "^4.6.4"
},
"dependencies": {
"@tonic-foundation/transaction": "1.0.1",
"@tonic-foundation/utils": "1.0.1",
"@tonic-foundation/transaction": "1.0.2",
"@tonic-foundation/utils": "1.0.2",
"bn.js": "^5.2.0",
"near-api-js": "^1.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tonic-foundation/token",
"homepage": "https://github.com/tonic-foundation/near-utils-ts",
"repository": "tonic-foundation/near-utils-ts",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"files": [
"lib"
Expand All @@ -19,8 +19,8 @@
"typescript": "^4.6.4"
},
"dependencies": {
"@tonic-foundation/transaction": "1.0.1",
"@tonic-foundation/utils": "1.0.1",
"@tonic-foundation/transaction": "1.0.2",
"@tonic-foundation/utils": "1.0.2",
"bn.js": "^5.2.1",
"near-api-js": "^1.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tonic-foundation/transaction",
"homepage": "https://github.com/tonic-foundation/near-utils-ts",
"repository": "tonic-foundation/near-utils-ts",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"files": [
"lib"
Expand All @@ -19,7 +19,7 @@
"typescript": "^4.6.4"
},
"dependencies": {
"@tonic-foundation/utils": "1.0.1",
"@tonic-foundation/utils": "1.0.2",
"bn.js": "^5.2.0",
"near-api-js": "^1.0.0"
}
Expand Down
43 changes: 43 additions & 0 deletions packages/transaction/src/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Functions for checking status of a transaction, including
* checking for errors in a promise chain.
*/
import { Near } from 'near-api-js';
import {
FinalExecutionOutcome,
JsonRpcProvider,
} from 'near-api-js/lib/providers';
import { ExecutionOutcome } from 'near-api-js/lib/providers/provider';

export function isErrorStatus(
s: ExecutionOutcome['status'] | FinalExecutionOutcome['status']
): boolean {
if (typeof s === 'string') {
return s === 'Failure';
}
return 'Failure' in s;
}

/**
*
* @param txId
* @returns true if success, false otherwise
*/
export async function didTxSucceed(
near: Near,
accountId: string,
txId: string
): Promise<boolean> {
// It's not exactly this. Actual rpc response has more fields, but we only
// need these fields for what we're doing. RPC will throw its own errors,
// so it's fine to use the type as is.
const ret: FinalExecutionOutcome = await (
near.connection.provider as JsonRpcProvider
).sendJsonRpc('EXPERIMENTAL_tx_status', [txId, accountId]);

const hasError = ret.receipts_outcome.some((o) => {
return isErrorStatus(o.outcome.status);
});

return !isErrorStatus(ret.status) && !hasError;
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tonic-foundation/utils",
"homepage": "https://github.com/tonic-foundation/near-utils-ts",
"repository": "tonic-foundation/near-utils-ts",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"files": [
"lib"
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@tonic-foundation/storage@workspace:packages/storage"
dependencies:
"@tonic-foundation/transaction": 1.0.1
"@tonic-foundation/utils": 1.0.1
"@tonic-foundation/transaction": 1.0.2
"@tonic-foundation/utils": 1.0.2
"@tsconfig/recommended": ^1.0.1
"@types/bn.js": ^5.1.0
bn.js: ^5.2.0
Expand All @@ -44,8 +44,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@tonic-foundation/token@workspace:packages/token"
dependencies:
"@tonic-foundation/transaction": 1.0.1
"@tonic-foundation/utils": 1.0.1
"@tonic-foundation/transaction": 1.0.2
"@tonic-foundation/utils": 1.0.2
"@tsconfig/recommended": ^1.0.1
"@types/bn.js": ^5.1.0
bn.js: ^5.2.1
Expand All @@ -54,12 +54,12 @@ __metadata:
languageName: unknown
linkType: soft

"@tonic-foundation/[email protected].1, @tonic-foundation/transaction@workspace:packages/transaction":
"@tonic-foundation/[email protected].2, @tonic-foundation/transaction@workspace:packages/transaction":
version: 0.0.0-use.local
resolution: "@tonic-foundation/transaction@workspace:packages/transaction"
dependencies:
"@near-wallet-selector/core": ^7.0.0
"@tonic-foundation/utils": 1.0.1
"@tonic-foundation/utils": 1.0.2
"@tsconfig/recommended": ^1.0.1
"@types/bn.js": ^5.1.0
bn.js: ^5.2.0
Expand All @@ -68,7 +68,7 @@ __metadata:
languageName: unknown
linkType: soft

"@tonic-foundation/[email protected].1, @tonic-foundation/utils@workspace:packages/utils":
"@tonic-foundation/[email protected].2, @tonic-foundation/utils@workspace:packages/utils":
version: 0.0.0-use.local
resolution: "@tonic-foundation/utils@workspace:packages/utils"
dependencies:
Expand Down

0 comments on commit 44fda53

Please sign in to comment.