Skip to content

Commit afa8f14

Browse files
committed
Add base project.
1 parent 33f6d71 commit afa8f14

14 files changed

+3142
-1
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": [
5+
"@typescript-eslint"
6+
],
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"plugin:prettier/recommended"
12+
],
13+
"rules": {
14+
"semi": "off",
15+
"@typescript-eslint/semi": ["error"],
16+
"no-shadow": "off",
17+
"@typescript-eslint/no-shadow": "error",
18+
"@typescript-eslint/no-unused-vars": "error",
19+
"no-console": 0,
20+
"no-empty": ["error", { "allowEmptyCatch": true }],
21+
"no-buffer-constructor": 0,
22+
"no-case-declarations": 0,
23+
"no-useless-escape": 0,
24+
"indent": "off",
25+
"object-curly-spacing": [
26+
"error",
27+
"always",
28+
{
29+
"objectsInObjects": true
30+
}
31+
],
32+
"no-undef": 0,
33+
"require-atomic-updates": 0,
34+
"no-async-promise-executor": 0,
35+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
36+
"@typescript-eslint/explicit-function-return-type": "warn",
37+
"@typescript-eslint/ban-ts-comment": "off",
38+
"@typescript-eslint/no-non-null-assertion": "off"
39+
}
40+
}

.gitignore

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# IDEs and editors
33+
.idea
34+
.project
35+
.classpath
36+
.c9/
37+
*.launch
38+
.settings/
39+
*.sublime-workspace
40+
41+
# IDE - VSCode
42+
.vscode/*
43+
!.vscode/settings.json
44+
!.vscode/tasks.json
45+
!.vscode/launch.json
46+
!.vscode/extensions.json
47+
48+
# misc
49+
.sass-cache
50+
connect.lock
51+
typings
52+
53+
# Logs
54+
logs
55+
*.log
56+
npm-debug.log*
57+
yarn-debug.log*
58+
yarn-error.log*
59+
60+
61+
# Dependency directories
62+
node_modules/
63+
jspm_packages/
64+
65+
# Optional npm cache directory
66+
.npm
67+
68+
# Optional eslint cache
69+
.eslintcache
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variables file
81+
.env
82+
83+
# next.js build output
84+
.next
85+
86+
# Lerna
87+
lerna-debug.log
88+
89+
# System Files
90+
.DS_Store
91+
Thumbs.db

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bracketSpacing": true,
3+
"bracketSameLine": true,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"useTabs": true,
7+
"tabWidth": 2,
8+
"semi": true
9+
}

README.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
11
# raw-transaction-decoder
2-
A utility for decoding raw Bitcoin transactions
2+
3+
This project is a utility for decoding raw Bitcoin transactions. It is written in TypeScript and uses the bitcoinjs-lib library.
4+
5+
The `decodeRawTx` method used here is modified from [this source](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1606#issuecomment-664740672)
6+
7+
## Installation
8+
9+
```bash
10+
# Using Yarn
11+
yarn add @synonymdev/raw-transaction-decoder
12+
13+
# Or, using NPM
14+
npm i -S @synonymdev/raw-transaction-decoder
15+
```
16+
17+
## Usage
18+
19+
Here's a basic example of how to use the `decodeRawTx` function:
20+
21+
```typescript
22+
import decodeRawTx from '@synonymdev/raw-transaction-decoder';
23+
24+
// replace with your raw transaction
25+
const rawTx = '02000000000101f52c85da1f8a30d49553f9cf0294a101c50c4a293bcc6bb48056ff2dc69545090000000000ffffffff02e4190f000000000016001425095b84d1f12033921a231de7fe515186fd04a81027000000000000160014a975f412cb9ddc9dc7f9fad0f7467bd801de4ffc0247304402201b239445ff572a79a4e6e0823bb42a57762582a6b42ce182200d99ba9a9e077502202c48938d1f735ab1c2c7e2a96d7bcfcd97a9c7b51f03aae8f15942b4c8cb1b87012103972490b241e5c788a3b544f08cf05ad925c2d79371747d2fbd06d7df477cb1e800000000';
26+
27+
// replace with your network (bitcoin, testnet or regtest)
28+
const network = 'regtest';
29+
30+
const result = decodeRawTx(rawTx, network);
31+
32+
if (result.isErr()) {
33+
console.error(result.error.message);
34+
return;
35+
}
36+
console.log(result.value);
37+
```
38+
39+
For an example response, please see [DECODED_TRANSACTION](./tests/constants.ts).
40+
41+
## Running Tests & Examples
42+
43+
### Clone the Repository
44+
45+
```bash
46+
git clone [email protected]:synonymdev/raw-transaction-decoder.git && cd raw-transaction-decoder
47+
```
48+
49+
### Install Dependencies & Build
50+
51+
```bash
52+
npm i && npm run build
53+
```
54+
55+
### Run tests:
56+
57+
```bash
58+
npm run test
59+
```
60+
61+
### Run example project:
62+
```bash
63+
npm run example
64+
```
65+

example/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import decodeRawTx from '../src';
2+
import { NETWORK, RAW_TRANSACTION } from '../tests/constants';
3+
4+
const runExample = async (): Promise<void> => {
5+
const decodedTx = decodeRawTx(RAW_TRANSACTION, NETWORK);
6+
if (decodedTx.isErr()) {
7+
console.log('Error:', decodedTx.error);
8+
return;
9+
}
10+
console.log('Decoded Transaction:\n');
11+
console.dir(decodedTx.value, { depth: null });
12+
};
13+
14+
runExample().then();

0 commit comments

Comments
 (0)