Skip to content

Commit

Permalink
Feature/xlm (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruckim authored Jan 29, 2022
1 parent 75afd1c commit 0a89bba
Show file tree
Hide file tree
Showing 47 changed files with 1,183 additions and 201 deletions.
4 changes: 4 additions & 0 deletions examples/xlm-example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../.examples.eslintrc.json"],
"ignorePatterns": ["!**/*"]
}
14 changes: 14 additions & 0 deletions examples/xlm-example/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'xlm-example',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/examples/xlm-example',
}
5 changes: 5 additions & 0 deletions examples/xlm-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@tatumio/xlm-example",
"version": "0.0.1",
"type": "commonjs"
}
31 changes: 31 additions & 0 deletions examples/xlm-example/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"root": "examples/xlm-example",
"sourceRoot": "examples/xlm-example/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/examples/xlm-example",
"main": "examples/xlm-example/src/index.ts",
"tsConfig": "examples/xlm-example/tsconfig.app.json",
"packageJson": "examples/xlm-example/package.json"
}
},
"serve": {
"executor": "@nrwl/node:execute",
"options": {
"buildTarget": "xlm-example:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["examples/xlm-example/**/*.ts"]
}
}
},
"tags": ["type:example"]
}
47 changes: 47 additions & 0 deletions examples/xlm-example/src/app/xlm.api.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumXlmSDK } from '@tatumio/xlm'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmApiExample() {
const wallet = await xlmSDK.api.xlmWallet()

const info = await xlmSDK.api.xlmGetLastClosedLedger()

const ledger = await xlmSDK.api.xlmGetLedger('1')

const ledgerTransactions = await xlmSDK.api.xlmGetLedgerTx('1')

const fee = await xlmSDK.api.xlmGetFee()

const transactions = await xlmSDK.api.xlmGetAccountTx(
'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
)

const tx = await xlmSDK.api.xlmGetTransaction(
'1A32A054B04AC9D6814710DDCA416E72C4CD2D78D6C3DFC06CC9369CC4F6B250',
)

const account = await xlmSDK.api.xlmGetAccountInfo(
'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
)

const transferTxId = await xlmSDK.api.xlmTransferBlockchain({
fromAccount: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
to: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
amount: '10000',
fromSecret: 'SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED',
})

const trustLineTxId = await xlmSDK.api.xlmTrustLineBlockchain({
fromAccount: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
issuerAccount: 'GC5LAVZ5UPLIFDH6SI33PNVL5TKWA4ODXTI3WEF5JM6LRM5MNGVJ56TT',
limit: '1000',
token: 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709',
fromSecret: 'SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED',
})

const broadcastTxId = await xlmSDK.api.xlmBroadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
})
}
30 changes: 30 additions & 0 deletions examples/xlm-example/src/app/xlm.blockchain.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumXlmSDK } from '@tatumio/xlm'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmBlockchainExample() {
const account = await xlmSDK.blockchain.getAccountInfo(
'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
)

const broadcastTxId = await xlmSDK.blockchain.broadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
})

const currentLedger = await xlmSDK.blockchain.getCurrentLedger()

const fee = await xlmSDK.blockchain.getFee()

const ledger = await xlmSDK.blockchain.getLedger('1')

const transactions = await xlmSDK.blockchain.getLedgerTx('1')

const transaction = await xlmSDK.blockchain.getTransaction(
'749e4f8933221b9942ef38a02856803f379789ec8d971f1f60535db70135673e',
)

const accountTransactions = await xlmSDK.blockchain.getAccountTransactions(
'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
)
}
22 changes: 22 additions & 0 deletions examples/xlm-example/src/app/xlm.kms.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumXlmSDK } from '@tatumio/xlm'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmKmsExample() {
const pendingSignatureIds = await xlmSDK.kms.getAllPending()
const tx = await xlmSDK.kms.get(pendingSignatureIds.id)

await xlmSDK.kms.complete(pendingSignatureIds.id, pendingSignatureIds.txId!)
await xlmSDK.kms.delete(pendingSignatureIds.id)

const transaction = await xlmSDK.kms.sign(
{
id: pendingSignatureIds.id,
hashes: pendingSignatureIds.hashes,
serializedTransaction: pendingSignatureIds.serializedTransaction,
},
'SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED',
true,
)
}
164 changes: 164 additions & 0 deletions examples/xlm-example/src/app/xlm.ledger.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumXlmSDK } from '@tatumio/xlm'
import { Currency } from '@tatumio/shared-core'
import { CreateTrade, VirtualCurrency } from '@tatumio/api-client'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export const xlmLedgerAccountExample = async () => {
const account = await xlmSDK.ledger.account.create({
currency: Currency.XLM,
})
await xlmSDK.ledger.account.activate('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.account.createMultiple({
accounts: [{ currency: Currency.XLM }, { currency: Currency.XLM }],
})
await xlmSDK.ledger.account.deactivate('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.account.freeze('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.account.unfreeze('5e6be89ee6aa436299950c3f')
await xlmSDK.ledger.account.update('5e6be89ee6aa436299950c3f', {
accountCode: 'AC_1011_B',
accountNumber: '123456',
})

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

export const xlmLedgerCustomerExample = async () => {
await xlmSDK.ledger.customer.activate('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.customer.deactivate('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.customer.disable('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.customer.enable('5e68c66581f2ee32bc354087')

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

export const xlmLedgerOrderBookExample = async () => {
await xlmSDK.ledger.orderBook.cancel('5e68c66581f2ee32bc354087')
await xlmSDK.ledger.orderBook.cancelByAccount('5e68c66581f2ee32bc354087')

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

export const xlmLedgerTransactionExample = async () => {
const transaction = await xlmSDK.ledger.transaction.countByAccount({
id: '5e6be8e9e6aa436299950c41',
})
const transactionByCustomer = await xlmSDK.ledger.transaction.countByCustomer({
id: '5e6be8e9e6aa436299950c41',
})
const transactions = await xlmSDK.ledger.transaction.getAll({})

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

export const xlmLedgerVirtualCurrencyExample = async () => {
const virtualCurrencyAcc = await xlmSDK.ledger.virtualCurrency.create({
name: 'VC_VIRTUAL',
supply: '1000000',
basePair: VirtualCurrency.basePair.XLM,
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 xlmSDK.ledger.virtualCurrency.getByName('VC_VIRTUAL')
const mintTx = await xlmSDK.ledger.virtualCurrency.mint({
accountId: '5e68c66581f2ee32bc354087',
amount: '1.5',
})
const revokeTx = await xlmSDK.ledger.virtualCurrency.revoke({
accountId: '5e68c66581f2ee32bc354087',
amount: '1.5',
})
await xlmSDK.ledger.virtualCurrency.update({
name: 'VC_VIRTUAL',
baseRate: 1,
basePair: VirtualCurrency.basePair.EUR,
})
}

export const xlmLedgerBlockAmountExample = async () => {
const accountId = await xlmSDK.ledger.blockAmount.block('5e6be89ee6aa436299950c3f', {
amount: '5',
type: 'DEBIT_CARD_OP',
description: 'Card payment in the shop.',
})
const txResult = await xlmSDK.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 xlmSDK.ledger.blockAmount.unblock('5e6be89ee6aa436299950c3f')
}
38 changes: 38 additions & 0 deletions examples/xlm-example/src/app/xlm.offchain.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { TatumXlmSDK } from '@tatumio/xlm'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmOffchainExample() {
const account = await xlmSDK.offchain.depositAddress.checkExists(
'qzla5ev0pap3yrvr0t77k4sjerhr8l3a6sh98gqqya',
)
const address = await xlmSDK.offchain.depositAddress.create('5e68c66581f2ee32bc354087', 1)
const adresses = await xlmSDK.offchain.depositAddress.createMultiple({
addresses: [
{
accountId: '5e6be8e9e6aa436299950c41',
derivationKey: 0,
},
{
accountId: '5e6be8e9e6aa436299951n35',
derivationKey: 1,
},
],
})
const assignedAddress = await xlmSDK.offchain.depositAddress.assign(
'5e6be8e9e6aa436299950c41',
'7c21ed165e294db78b95f0f181086d6f',
)
const addressByAccount = await xlmSDK.offchain.depositAddress.getByAccount('5e6be8e9e6aa436299950c41')
await xlmSDK.offchain.depositAddress.remove('5e6be8e9e6aa436299950c41', '7c21ed165e294db78b95f0f181086d6f')
await xlmSDK.offchain.storeTokenAddress('7c21ed165e294db78b95f0f181086d6f', 'MY_TOKEN')
const withdrawals = await xlmSDK.offchain.withdrawal.getAll('Done')
await xlmSDK.offchain.sendOffchainTransaction(true, {
secret: 'SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED',
address: 'GDKYMXOAJ5MK4EVIHHNWRGAAOUZMNZYAETMHFCD6JCVBPZ77TUAZFPKT',
amount: '10000',
fee: '1000',
senderAccountId: '61b3bffddfb389cde19c73be',
})
}
10 changes: 10 additions & 0 deletions examples/xlm-example/src/app/xlm.root.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Fiat } from '@tatumio/shared-core'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'
import { TatumXlmSDK } from '@tatumio/xlm'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmChangeRateExample() {
const rate = await xlmSDK.getExchangeRate()
const rateWithBasePair = await xlmSDK.getExchangeRate(Fiat.EUR)
}
13 changes: 13 additions & 0 deletions examples/xlm-example/src/app/xlm.tx.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TatumXlmSDK } from '@tatumio/xlm'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmTxExample() {
await xlmSDK.transaction.sendTransaction(true, {
fromAccount: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
fromSecret: 'SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED',
amount: '10000',
to: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
})
}
8 changes: 8 additions & 0 deletions examples/xlm-example/src/app/xlm.wallet.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TatumXlmSDK } from '@tatumio/xlm'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const xlmSDK = TatumXlmSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function xlmWalletExample() {
const wallet = await xlmSDK.wallet()
}
Loading

0 comments on commit 0a89bba

Please sign in to comment.