Skip to content

Commit

Permalink
Add base project.
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyphillips committed Mar 6, 2024
1 parent 33f6d71 commit afa8f14
Show file tree
Hide file tree
Showing 14 changed files with 3,142 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
40 changes: 40 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"semi": "off",
"@typescript-eslint/semi": ["error"],
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-vars": "error",
"no-console": 0,
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-buffer-constructor": 0,
"no-case-declarations": 0,
"no-useless-escape": 0,
"indent": "off",
"object-curly-spacing": [
"error",
"always",
{
"objectsInObjects": true
}
],
"no-undef": 0,
"require-atomic-updates": 0,
"no-async-promise-executor": 0,
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.sass-cache
connect.lock
typings

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Lerna
lerna-debug.log

# System Files
.DS_Store
Thumbs.db
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bracketSpacing": true,
"bracketSameLine": true,
"singleQuote": true,
"trailingComma": "none",
"useTabs": true,
"tabWidth": 2,
"semi": true
}
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,65 @@
# raw-transaction-decoder
A utility for decoding raw Bitcoin transactions

This project is a utility for decoding raw Bitcoin transactions. It is written in TypeScript and uses the bitcoinjs-lib library.

The `decodeRawTx` method used here is modified from [this source](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1606#issuecomment-664740672)

## Installation

```bash
# Using Yarn
yarn add @synonymdev/raw-transaction-decoder

# Or, using NPM
npm i -S @synonymdev/raw-transaction-decoder
```

## Usage

Here's a basic example of how to use the `decodeRawTx` function:

```typescript
import decodeRawTx from '@synonymdev/raw-transaction-decoder';

// replace with your raw transaction
const rawTx = '02000000000101f52c85da1f8a30d49553f9cf0294a101c50c4a293bcc6bb48056ff2dc69545090000000000ffffffff02e4190f000000000016001425095b84d1f12033921a231de7fe515186fd04a81027000000000000160014a975f412cb9ddc9dc7f9fad0f7467bd801de4ffc0247304402201b239445ff572a79a4e6e0823bb42a57762582a6b42ce182200d99ba9a9e077502202c48938d1f735ab1c2c7e2a96d7bcfcd97a9c7b51f03aae8f15942b4c8cb1b87012103972490b241e5c788a3b544f08cf05ad925c2d79371747d2fbd06d7df477cb1e800000000';

// replace with your network (bitcoin, testnet or regtest)
const network = 'regtest';

const result = decodeRawTx(rawTx, network);

if (result.isErr()) {
console.error(result.error.message);
return;
}
console.log(result.value);
```

For an example response, please see [DECODED_TRANSACTION](./tests/constants.ts).

## Running Tests & Examples

### Clone the Repository

```bash
git clone [email protected]:synonymdev/raw-transaction-decoder.git && cd raw-transaction-decoder
```

### Install Dependencies & Build

```bash
npm i && npm run build
```

### Run tests:

```bash
npm run test
```

### Run example project:
```bash
npm run example
```

14 changes: 14 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import decodeRawTx from '../src';
import { NETWORK, RAW_TRANSACTION } from '../tests/constants';

const runExample = async (): Promise<void> => {
const decodedTx = decodeRawTx(RAW_TRANSACTION, NETWORK);
if (decodedTx.isErr()) {
console.log('Error:', decodedTx.error);
return;
}
console.log('Decoded Transaction:\n');
console.dir(decodedTx.value, { depth: null });
};

runExample().then();
Loading

0 comments on commit afa8f14

Please sign in to comment.