Skip to content

Commit

Permalink
Feature/btc based (#347)
Browse files Browse the repository at this point in the history
* chore: bch

* chore: ltc tx tests

* chore: ltc & bch refactoring

* chore: doge tx tests

* chore: cleanup

* feat:  scrypta

* refactor:  sonar fixes

Co-authored-by: Nick Papirniy <[email protected]>
  • Loading branch information
npwork and Nick Papirniy authored Jan 31, 2022
1 parent 0a89bba commit 3213dbb
Show file tree
Hide file tree
Showing 144 changed files with 2,525 additions and 1,133 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
"@typescript-eslint/ban-ts-comment": "off"
}
},
{
"files": ["*spec.ts"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {
"@typescript-eslint/no-empty-function": "off"
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
Expand Down
19 changes: 19 additions & 0 deletions CONRTIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# TBD

# Create library for new blockchain integration

## EVM Based

nx g @nrwl/js:library sdk-{BLOCKCHAIN_NAME} --directory=blockchain --simpleModuleName=true --buildable --publishable --importPath=@tatumio/{BLOCKCHAIN_NAME} --testEnvironment=node --tags=scope:sdk,scope:evm-based

## Btc Based

nx g @nrwl/js:library sdk-{BLOCKCHAIN_NAME} --directory=blockchain --simpleModuleName=true --buildable --publishable --importPath=@tatumio/{BLOCKCHAIN_NAME} --testEnvironment=node --tags=scope:sdk,scope:btc-based

## Other (not evm and not btc)

nx g @nrwl/js:library sdk-{BLOCKCHAIN_NAME} --directory=blockchain --simpleModuleName=true --buildable --publishable --importPath=@tatumio/{BLOCKCHAIN_NAME} --testEnvironment=node --tags=scope:sdk

# Check workspace.json file to make sure module has correct name

# Remove compilerOptions from packages/{BLOCKCHAIN_NAME}/tsconfig.json
48 changes: 0 additions & 48 deletions examples/bch-example/src/app/bch.api.example.ts

This file was deleted.

36 changes: 36 additions & 0 deletions examples/bch-example/src/app/bch.blockchain.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumBchSDK } from '@tatumio/bch'
import { BchTransaction } from '@tatumio/api-client'

const bchSDK = TatumBchSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bchBlockchainExample() {
const blockChainInfo = await bchSDK.blockchain.info()
const block = await bchSDK.blockchain.getBlock(
'0000000000000010da4dbada5440ec86dd74d0ade1920ac1897f9adcfe83f8b9',
)
const txHash = await bchSDK.blockchain.broadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6',
})
const hash = await bchSDK.blockchain.getBlockHash(1580117)
const tx = await bchSDK.blockchain.getTransaction(
'1451692ebbfbea1a2d2ec6fe6782596b6aa2e46c0589d04c406f491b5b46bc6a',
)
const txByAddress = await bchSDK.blockchain.getTxForAccount('2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb', 50)
const transfer = await bchSDK.blockchain.send({
fromUTXO: [
{
txHash: '53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc',
index: 0,
privateKey: 'cVX7YtgL5muLTPncHFhP95oitV1mqUUA5VeSn8HeCRJbPqipzobf',
},
],
to: [
{
address: '2MzNGwuKvMEvKMQogtgzSqJcH2UW3Tc5oc7',
value: 0.02969944,
},
],
} as BchTransaction)
}
66 changes: 36 additions & 30 deletions examples/bch-example/src/app/bch.tx.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,41 @@ import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
const bchSDK = TatumBchSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bchTransactionsExample() {
const txData = await bchSDK.transaction.prepareSignedTransaction(true, {
fromUTXO: [
{
txHash: 'fcdc23f5c8bd811195921cd113f5724f3cf8b3fa0287a04366c51b9e8545c4c7',
index: 0,
privateKey: 'L3Jf3gvX1YaCJJTejTfghZ4Sst8GSui6UQctERksAimYCskVH7iG',
},
],
to: [
{
address: 'qps4cv6gtxh7473qxzcwe6nk90canlt57cd57gpy08',
value: 0.00015,
},
],
})
const txData = await bchSDK.transaction.prepareSignedTransaction(
{
fromUTXO: [
{
txHash: 'fcdc23f5c8bd811195921cd113f5724f3cf8b3fa0287a04366c51b9e8545c4c7',
index: 0,
privateKey: 'L3Jf3gvX1YaCJJTejTfghZ4Sst8GSui6UQctERksAimYCskVH7iG',
},
],
to: [
{
address: 'qps4cv6gtxh7473qxzcwe6nk90canlt57cd57gpy08',
value: 0.00015,
},
],
},
{ testnet: true },
)

const { txId, failed } = await bchSDK.transaction.sendTransaction(true, {
fromUTXO: [
{
txHash: 'fcdc23f5c8bd811195921cd113f5724f3cf8b3fa0287a04366c51b9e8545c4c7',
index: 0,
privateKey: 'L3Jf3gvX1YaCJJTejTfghZ4Sst8GSui6UQctERksAimYCskVH7iG',
},
],
to: [
{
address: 'qps4cv6gtxh7473qxzcwe6nk90canlt57cd57gpy08',
value: 0.00015,
},
],
})
const { txId, failed } = await bchSDK.transaction.sendTransaction(
{
fromUTXO: [
{
txHash: 'fcdc23f5c8bd811195921cd113f5724f3cf8b3fa0287a04366c51b9e8545c4c7',
index: 0,
privateKey: 'L3Jf3gvX1YaCJJTejTfghZ4Sst8GSui6UQctERksAimYCskVH7iG',
},
],
to: [
{
address: 'qps4cv6gtxh7473qxzcwe6nk90canlt57cd57gpy08',
value: 0.00015,
},
],
},
{ testnet: true },
)
}
4 changes: 2 additions & 2 deletions examples/bch-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bchWalletExample } from './app/bch.wallet.example'
import { bchApiExample } from './app/bch.api.example'
import { bchBlockchainExample } from './app/bch.blockchain.example'
import { bchKmsExample } from './app/bch.kms.example'
import {
bchLedgerAccountsExample,
Expand All @@ -14,7 +14,7 @@ import { exchangeRateExample } from './app/bch.root.example'
import { bchTransactionsExample } from './app/bch.tx.example'

console.log(`Running ${bchWalletExample()}`)
console.log(`Running ${bchApiExample()}`)
console.log(`Running ${bchBlockchainExample()}`)
console.log(`Running ${bchKmsExample()}`)
console.log(`Running ${bchLedgerAccountsExample()}`)
console.log(`Running ${bchLedgerBlockAmountExample()}`)
Expand Down
5 changes: 2 additions & 3 deletions examples/bsc-example/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:package",
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/examples/bsc-example",
"main": "examples/bsc-example/src/index.ts",
"tsConfig": "examples/bsc-example/tsconfig.app.json",
"packageJson": "examples/bsc-example/package.json",
"assets": ["examples/bsc-example/*.md"]
"packageJson": "examples/bsc-example/package.json"
}
},
"serve": {
Expand Down
4 changes: 2 additions & 2 deletions examples/btc-example/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/examples/btc-example",
Expand All @@ -14,7 +14,7 @@
}
},
"serve": {
"executor": "@nrwl/node:execute",
"executor": "@nrwl/js:execute",
"options": {
"buildTarget": "btc-example:build"
}
Expand Down
52 changes: 0 additions & 52 deletions examples/btc-example/src/app/btc.api.example.ts

This file was deleted.

44 changes: 44 additions & 0 deletions examples/btc-example/src/app/btc.blockchain.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumBtcSDK } from '@tatumio/btc'
import { BtcTransactionFromAddress } from '@tatumio/api-client'

const btcSDK = TatumBtcSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function btcBlockchainExample() {
const mempoolTransactionIds = await btcSDK.blockchain.mempool()
const block = await btcSDK.blockchain.getBlock(
'0000000000000000000067de34da54c96ff76e6ba172f82c4ed8a25afb112a9e',
)
const txHash = await btcSDK.blockchain.broadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6',
})
const balance = await btcSDK.blockchain.getBlockchainAccountBalance('2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb')
const blockchainInfo = await btcSDK.blockchain.info()
const hash = await btcSDK.blockchain.getBlockHash(1580117)
const tx = await btcSDK.blockchain.getTransaction(
'1451692ebbfbea1a2d2ec6fe6782596b6aa2e46c0589d04c406f491b5b46bc6a',
)
const txByAddress = await btcSDK.blockchain.getTransactionsByAddress(
'2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb',
50,
)
const utxo = await btcSDK.blockchain.getUTXO(
'53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc',
0,
)
const transfer = await btcSDK.blockchain.sendTransaction({
fromAddress: [
{
address: '2N9bBiH2qrTDrPCzrNhaFGdkNKS86PJAAAS',
privateKey: 'cVX7YtgL5muLTPncHFhP95oitV1mqUUA5VeSn8HeCRJbP',
},
],
to: [
{
address: '2MzNGwuKvMEvKMQogtgzSqJcH2UW3Tc5oc7',
value: 0.02969944,
},
],
} as BtcTransactionFromAddress)
}
Loading

0 comments on commit 3213dbb

Please sign in to comment.