Skip to content

Commit

Permalink
Add missing examples btc based (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakcinmarina authored Jan 26, 2022
1 parent b4e0fde commit c55ee29
Show file tree
Hide file tree
Showing 20 changed files with 872 additions and 44 deletions.
21 changes: 21 additions & 0 deletions examples/bch-example/src/app/bch.api.example.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 })

Expand All @@ -8,4 +9,24 @@ export async function bchApiExample() {
const block = await bchSDK.api.bchGetBlock(
'0000000000000010da4dbada5440ec86dd74d0ade1920ac1897f9adcfe83f8b9',
)
const txHash = await bchSDK.api.bchBroadcast({ txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D', signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6' });
const address = await bchSDK.api.bchGenerateAddress('xpub6EsCk1uU6cJzqvP9CdsTiJwT2rF748YkPnhv5Qo8q44DG7nn2vbyt48YRsNSUYS44jFCW9gwvD9kLQu9AuqXpTpM1c5hgg9PsuBLdeNncid', 0);
const privateKey = await bchSDK.api.bchGenerateAddressPrivateKey({ mnemonic: 'urge pulp usage sister evidence arrest palm math please chief egg abuse', index: 0 });
const wallet = await bchSDK.api.bchGenerateWallet('urge pulp usage sister evidence arrest palm math please chief egg abuse');
const blockchainInfo = await bchSDK.api.bchGetBlockChainInfo();
const hash = await bchSDK.api.bchGetBlockHash(1580117);
const tx = await bchSDK.api.bchGetRawTransaction('1451692ebbfbea1a2d2ec6fe6782596b6aa2e46c0589d04c406f491b5b46bc6a');
const txByAddress = await bchSDK.api.bchGetTxByAddress('2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb', 50);
const transfer = await bchSDK.api.bchTransferBlockchain({
fromUTXO: [{
txHash: "53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc",
index: 0,
privateKey: "cVX7YtgL5muLTPncHFhP95oitV1mqUUA5VeSn8HeCRJbPqipzobf"
}], to: [
{
address: "2MzNGwuKvMEvKMQogtgzSqJcH2UW3Tc5oc7",
value: 0.02969944
}
]
} as BchTransaction);
}
162 changes: 157 additions & 5 deletions examples/bch-example/src/app/bch.ledger.example.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,163 @@
import { TatumBchSDK } from '@tatumio/bch'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { Currency } from '@tatumio/shared-core'
import { TatumBchSDK } from '@tatumio/bch';
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing';
import { Currency } from '@tatumio/shared-core';
import { CreateTrade, VirtualCurrency } from '@tatumio/api-client';

const bchSDK = TatumBchSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })
const bchSDK = TatumBchSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY });

export async function bchLedgerAccountsExample() {
const account = await bchSDK.ledger.account.create({
currency: Currency.BCH,
})
});
await bchSDK.ledger.account.activate('5e68c66581f2ee32bc354087');
await bchSDK.ledger.account.createMultiple({
accounts: [
{ currency: Currency.BCH },
{ currency: Currency.BCH },
]
});
await bchSDK.ledger.account.deactivate('5e68c66581f2ee32bc354087');
await bchSDK.ledger.account.freeze('5e68c66581f2ee32bc354087');
await bchSDK.ledger.account.unfreeze('5e6be89ee6aa436299950c3f');
await bchSDK.ledger.account.update('5e6be89ee6aa436299950c3f', {
accountCode: "AC_1011_B",
accountNumber: "123456"
});

const accountById = await bchSDK.ledger.account.get('5e68c66581f2ee32bc354087');
const accounts = await bchSDK.ledger.account.getAll(10);
const balance = await bchSDK.ledger.account.getBalance('5e68c66581f2ee32bc354087');
const blockedAmount = await bchSDK.ledger.account.getBlockedAmountsByAccountId('5e68c66581f2ee32bc354087');
const customerAccounts = await bchSDK.ledger.account.getByCustomerId(10, '5e6be89ee6aa436299950c3f');
}

export async function bchLedgerBlockAmountExample() {
const accountId = await bchSDK.ledger.blockAmount.block('5e6be89ee6aa436299950c3f', {
amount: "5",
type: "DEBIT_CARD_OP",
description: "Card payment in the shop."
});
const txResult = await bchSDK.ledger.blockAmount.unblockWithTransaction('5e6be89ee6aa436299950c3f', {
recipientAccountId: "5e6645712b55823de7ea82f2",
amount: "5",
anonymous: false,
compliant: false,
transactionCode: "1_01_EXTERNAL_CODE",
paymentId: "9625",
recipientNote: "Private note",
baseRate: 1,
senderNote: "Sender note"
});
await bchSDK.ledger.blockAmount.unblock('5e6be89ee6aa436299950c3f');
}

export async function bchLedgerCustomerExample() {
await bchSDK.ledger.customer.activate('5e68c66581f2ee32bc354087');
await bchSDK.ledger.customer.deactivate('5e68c66581f2ee32bc354087');
await bchSDK.ledger.customer.disable('5e68c66581f2ee32bc354087');
await bchSDK.ledger.customer.enable('5e68c66581f2ee32bc354087');

const customer = await bchSDK.ledger.customer.get('5e68c66581f2ee32bc354087');
const customers = await bchSDK.ledger.customer.getAll(10);
const updatedCustomer = await bchSDK.ledger.customer.update('5e68c66581f2ee32bc354087', {
externalId: "123654",
});
}

export async function bchLedgerOrderbookExample() {
await bchSDK.ledger.orderBook.cancel('5e68c66581f2ee32bc354087');
await bchSDK.ledger.orderBook.cancelByAccount('5e68c66581f2ee32bc354087');

const trade = await bchSDK.ledger.orderBook.get('7c21ed165e294db78b95f0f1');
const activeBuyTrades = await bchSDK.ledger.orderBook.getActiveBuyTrades({
id: "7c21ed165e294db78b95f0f1",
customerId: "5e68c66581f2ee32bc354087",
pageSize: 10,
});
const activeSellTrades = await bchSDK.ledger.orderBook.getActiveSellTrades({
id: "7c21ed165e294db78b95f0f1",
customerId: "5e68c66581f2ee32bc354087",
pageSize: 10,
});
const historicalTrades = await bchSDK.ledger.orderBook.getHistorical({
id: "7c21ed165e294db78b95f0f1",
customerId: "5e68c66581f2ee32bc354087",
pageSize: 10,
});
const newTrade = await bchSDK.ledger.orderBook.newTrade({
type: CreateTrade.type.BUY,
price: "8650.4",
amount: "15000",
pair: "BCH/EUR",
currency1AccountId: "7c21ed165e294db78b95f0f1",
currency2AccountId: "7c21ed165e294db78b95f0f1",
feeAccountId: "7c21ed165e294db78b95f0f1",
fee: 1.5,
attr: {
sealDate: 1572031674384,
percentBlock: 1.5,
percentPenalty: 1.5
}
});
}

export async function bchLedgerTransactionExample() {
const transaction = await bchSDK.ledger.transaction.countByAccount({
id: '5e6be8e9e6aa436299950c41'
});
const transactionByCustomer = await bchSDK.ledger.transaction.countByCustomer({
id: '5e6be8e9e6aa436299950c41'
});
const transactions = await bchSDK.ledger.transaction.getAll({});

const transactionByAccount = await bchSDK.ledger.transaction.getAllByAccount({ id: '5e6645712b55823de7ea82f1' });
const transactionByCUstomer = await bchSDK.ledger.transaction.getAllByCustomer({
id: '5e6be8e9e6aa436299950c41'
});
const transactionByReference = await bchSDK.ledger.transaction.getAllByReference('5e6be8e9e6aa436299950c41');
const transactionResult = await bchSDK.ledger.transaction.send({
senderAccountId: "5e6645712b55823de7ea82f1",
recipientAccountId: "5e6645712b55823de7ea82f2",
amount: "5",
});
const batchTxResult = await bchSDK.ledger.transaction.sendMultiple({
senderAccountId: '5e6645712b55823de7ea82f1',
transaction: [{
recipientAccountId: "5e6645712b55823de7ea82f2",
amount: "5",
}]
});
}

export async function bchLedgerVirtualCurrencyExample() {
const virtualCurrencyAcc = await bchSDK.ledger.virtualCurrency.create({
name: "VC_VIRTUAL",
supply: "1000000",
basePair: VirtualCurrency.basePair.BCH,
baseRate: 1,
customer: {
accountingCurrency: VirtualCurrency.accountingCurrency.USD,
customerCountry: "US",
externalId: "123654",
providerCountry: "US"
},
description: "My Virtual Token description.",
accountCode: "AC_1011_B",
accountNumber: "1234567890",
accountingCurrency: VirtualCurrency.accountingCurrency.USD
});
const virtualCurrency = await bchSDK.ledger.virtualCurrency.getByName('VC_VIRTUAL');
const mintTx = await bchSDK.ledger.virtualCurrency.mint({
accountId: "5e68c66581f2ee32bc354087",
amount: "1.5",
});
const revokeTx = await bchSDK.ledger.virtualCurrency.revoke({
accountId: "5e68c66581f2ee32bc354087",
amount: "1.5",
});
await bchSDK.ledger.virtualCurrency.update({
name: "VC_VIRTUAL",
baseRate: 1,
basePair: VirtualCurrency.basePair.EUR
});
}
17 changes: 17 additions & 0 deletions examples/bch-example/src/app/bch.offchain.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@ const bchSDK = TatumBchSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bchOffchainExample() {
const account = await bchSDK.offchain.depositAddress.checkExists('qzla5ev0pap3yrvr0t77k4sjerhr8l3a6sh98gqqya')
const address = await bchSDK.offchain.depositAddress.create('5e68c66581f2ee32bc354087', 1);
const adresses = await bchSDK.offchain.depositAddress.createMultiple({
addresses: [
{
accountId: "5e6be8e9e6aa436299950c41",
derivationKey: 0
},
{
accountId: "5e6be8e9e6aa436299951n35",
derivationKey: 1
}
]
});
const assignedAddress = await bchSDK.offchain.depositAddress.assign('5e6be8e9e6aa436299950c41', '7c21ed165e294db78b95f0f181086d6f');
const addressByAccount = await bchSDK.offchain.depositAddress.getByAccount('5e6be8e9e6aa436299950c41');
await bchSDK.offchain.depositAddress.remove('5e6be8e9e6aa436299950c41', '7c21ed165e294db78b95f0f181086d6f');
await bchSDK.offchain.storeTokenAddress('7c21ed165e294db78b95f0f181086d6f', 'MY_TOKEN');
const withdrawals = await bchSDK.offchain.withdrawal.getAll('Done')
}
14 changes: 13 additions & 1 deletion examples/bch-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { bchWalletExample } from './app/bch.wallet.example'
import { bchApiExample } from './app/bch.api.example'
import { bchKmsExample } from './app/bch.kms.example'
import { bchLedgerAccountsExample } from './app/bch.ledger.example'
import {
bchLedgerAccountsExample,
bchLedgerBlockAmountExample,
bchLedgerCustomerExample,
bchLedgerOrderbookExample,
bchLedgerTransactionExample,
bchLedgerVirtualCurrencyExample
} from './app/bch.ledger.example'
import { bchOffchainExample } from './app/bch.offchain.example'
import { exchangeRateExample } from './app/bch.root.example'
import { bchTransactionsExample } from './app/bch.tx.example'
Expand All @@ -10,6 +17,11 @@ console.log(`Running ${bchWalletExample()}`)
console.log(`Running ${bchApiExample()}`)
console.log(`Running ${bchKmsExample()}`)
console.log(`Running ${bchLedgerAccountsExample()}`)
console.log(`Running ${bchLedgerBlockAmountExample()}`)
console.log(`Running ${bchLedgerCustomerExample()}`)
console.log(`Running ${bchLedgerOrderbookExample()}`)
console.log(`Running ${bchLedgerTransactionExample()}`)
console.log(`Running ${bchLedgerVirtualCurrencyExample()}`)
console.log(`Running ${bchOffchainExample()}`)
console.log(`Running ${exchangeRateExample()}`)
console.log(`Running ${bchTransactionsExample()}`)
32 changes: 27 additions & 5 deletions examples/btc-example/src/app/btc.api.example.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumBtcSDK } from '@tatumio/btc'
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 })
const btcSDK = TatumBtcSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY });

export async function btcApiExample() {
const mempoolTransactionIds = await btcSDK.api.btcGetMempool()
const mempoolTransactionIds = await btcSDK.api.btcGetMempool();
const block = await btcSDK.api.btcGetBlock(
'0000000000000000000067de34da54c96ff76e6ba172f82c4ed8a25afb112a9e',
)
);
const txHash = await btcSDK.api.btcBroadcast({ txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D', signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6' });
const address = await btcSDK.api.btcGenerateAddress('xpub6EsCk1uU6cJzqvP9CdsTiJwT2rF748YkPnhv5Qo8q44DG7nn2vbyt48YRsNSUYS44jFCW9gwvD9kLQu9AuqXpTpM1c5hgg9PsuBLdeNncid', 0);
const privateKey = await btcSDK.api.btcGenerateAddressPrivateKey({ mnemonic: 'urge pulp usage sister evidence arrest palm math please chief egg abuse', index: 0 });
const wallet = await btcSDK.api.btcGenerateWallet('urge pulp usage sister evidence arrest palm math please chief egg abuse');
const balance = await btcSDK.api.btcGetBalanceOfAddress('2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb');
const blockchainInfo = await btcSDK.api.btcGetBlockChainInfo();
const hash = await btcSDK.api.btcGetBlockHash(1580117);
const tx = await btcSDK.api.btcGetRawTransaction('1451692ebbfbea1a2d2ec6fe6782596b6aa2e46c0589d04c406f491b5b46bc6a');
const txByAddress = await btcSDK.api.btcGetTxByAddress('2MsM67NLa71fHvTUBqNENW15P68nHB2vVXb', 50);
const utxo = await btcSDK.api.btcGetUtxo('53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc', 0);
const transfer = await btcSDK.api.btcTransferBlockchain({
fromAddress: [{
address: "2N9bBiH2qrTDrPCzrNhaFGdkNKS86PJAAAS",
privateKey: "cVX7YtgL5muLTPncHFhP95oitV1mqUUA5VeSn8HeCRJbP"
}], to: [
{
address: "2MzNGwuKvMEvKMQogtgzSqJcH2UW3Tc5oc7",
value: 0.02969944
}
]
} as BtcTransactionFromAddress);
}
Loading

0 comments on commit c55ee29

Please sign in to comment.