Skip to content

Commit

Permalink
update (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeyDev310 authored Sep 21, 2021
1 parent 043bf16 commit 5982b2f
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.25.9",
"version": "1.25.10",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
38 changes: 38 additions & 0 deletions src/blockchain/algo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import BigNumber from 'bignumber.js'
import {get, post} from '../connector/tatum'
import {AlgoBlock, AlgoTx, TransactionHash} from '../model'

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandBroadcast" target="_blank">Tatum API documentation</a>
*/
export const algorandBroadcast = async (txData: string, signatureId?: string): Promise<TransactionHash> =>
post(`/v3/algorand/broadcast`, {txData, signatureId})

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandGetTransactionCount" target="_blank">Tatum API documentation</a>
*/
export const algorandGetTransactionsCount = async (address: string): Promise<number> =>
get(`/v3/algorand/transaction/count/${address}`)

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandGetCurrentBlock" target="_blank">Tatum API documentation</a>
*/
export const algorandGetCurrentBlock = async (): Promise<number> =>
get(`/v3/algorand/block/current`)

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandGetBlock" target="_blank">Tatum API documentation</a>
*/
export const algorandGetBlock = async (roundNumber: string): Promise<AlgoBlock> =>
get(`/v3/algorand/block/${roundNumber}`)

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandGetBalance" target="_blank">Tatum API documentation</a>
*/
export const algorandGetAccountBalance = async (address: string): Promise<BigNumber> =>
get(`/v3/algorand/account/balance/${address}`)

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/AlgorandGetTransaction" target="_blank">Tatum API documentation</a>
*/
export const algorandGetTransaction = async (txid: string): Promise<AlgoTx> => get(`/v3/algorand/transaction/${txid}`)
1 change: 1 addition & 0 deletions src/blockchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './tron'
export * from './xdc'
export * from './qtum'
export * from './egld'
export * from './algo'
99 changes: 99 additions & 0 deletions src/model/response/algo/AlgoBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {AlgoTx} from './AlgoTx'

/**
*
* @export
* @interface AlgoBlock
*/
export interface AlgoBlock {
/**
* [gh]hash to which this block belongs.
* @type {string}
* @memberof AlgoBlock
*/
genesisHash: string;

/**
* [gen] ID hash to which this block belongs.
* @type {string}
* @memberof AlgoBlock
*/
genesisId: string;

/**
* [prev] Previous block hash.
* @type {string}
* @memberof AlgoBlock
*/
previousBlockHash: string;

/**
* (optional)
* @type {any}
* @memberof AlgoBlock
*/
rewards: any;

/**
* [rnd] Current round on which this block was appended to the chain.
* @type {string}
* @memberof AlgoBlock
*/
round: string;

/**
* [seed] Sortition seed.
* @type {string}
* @memberof AlgoBlock
*/
seed: string;

/**
* [ts] Block creation timestamp in seconds since eposh.
* @type {number}
* @memberof AlgoBlock
*/
timestamp: number;

/**
* [txns]list of transactions corresponding to a given round.
* @type {Array<AlgoTx>}
* @memberof AlgoBlock
*/
txns: AlgoTx[];

/**
* [txn] TransactionsRoot authenticates the set of transactions appearing in the block.
* More specifically, it's the root of a merkle tree whose leaves are the block's Txids, in lexicographic order.
* For the empty block, it's 0.
* Note that the TxnRoot does not authenticate the signatures on the transactions, only the transactions themselves.
* Two blocks with the same transactions but in a different order and with different order and with different signatures will have the same TxnRot.
* @type {string}
* @memberof AlgoBlock
*/
txn: string;

/**
* [tc] TxnCounter counts the number of transactions committed in the ledger, from the time at which support for this feature was introduced.
* (optional)
* @type {number}
* @memberof AlgoBlock
*/
txnc: number;

/**
* (optional)
* @type {any}
* @memberof AlgoBlock
*/

upgradeState: any;

/**
* (optional)
* @type {any}
* @memberof AlgoBlock
*/
upgradeVote: any;

}
142 changes: 142 additions & 0 deletions src/model/response/algo/AlgoTx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
*
* @export
* @interface AlgoTx
*/
export interface AlgoTx {
/**
* [rc] rewards applied to close-remainder-to account.
* @type {number}
* @memberof AlgoTx
*/
closeRewards: number;

/**
* [ca]closing amount for transaction.
* @type {number}
* @memberof AlgoTx
*/
closingAmount: number;

/**
* Round when the transaction was confirmed.
* @type {number}
* @memberof AlgoTx
*/
confirmedRound: number;

/**
* [fee] Transaction fee.
* @type {number}
* @memberof AlgoTx
*/
fee: number;

/**
* [fv] First valid round for this transaction.
* @type {number}
* @memberof AlgoTx
*/
firstValid: number;

/**
* [gh] Hash of genesis block.
* @type {string}
* @memberof AlgoTx
*/

genisisHash: string;

/**
* [gen] genesis block ID.
* @type {string}
* @memberof AlgoTx
*/
genesisId: string;

/**
* Transaction ID.
* @type {string}
* @memberof AlgoTx
*/
id: string;

/**
* Offset into the round where this transaction was confirmed.
* @type {number}
* @memberof AlgoTx
*/
intraRoundOffset: number;

/**
* [lv] Last valid round for this transation.
* @type {number}
* @memberof AlgoTx
*/
lastValid: number;

/**
* [note] Free form data.
* @type {string}
* @memberof AlgoTx
*/
note: string;

/**
* optional
* @type {any}
* @memberof AlgoTx
*/
paymentTransaction: any;

/**
* [rr] rewards applied to receiver account
* @type {number}
* @memberof AlgoTx
*/
receiverRewards: number;

/**
* Time when the block this transaction is in was confirmed.
* @type {number}
* @memberof AlgoTx
*/
roundTime: number;

/**
* [snd] Sender's address
* @type {string}
* @memberof AlgoTx
*/
sender: string;

/**
* [rs] rewards applied to sender account
* @type {number}
* @memberof AlgoTx
*/
senderRewards: number;

/**
* signature
* @type {any}
* @memberof AlgoTx
*/
signature: any;

/**
* [type] Indicates what type of transaction this is. Different types have different fields.
*
* Valid types, and where their fields are stored:
* [pay] payment-transaction
* [keyreg] keyreg-transaction
* [acfg] asset-config-transaction
* [axfer] asset-transfer-transaction
* [afrz] asset-freeze-transaction
* [appl] application-transaction
*
* @type {string}
* @memberof AlgoTx
*/
txType: string;
}
2 changes: 2 additions & 0 deletions src/model/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ export * from './qtum/QtumBlock'
export * from './ledger/Customer'
export * from './one/OneTx'
export * from './egld'
export * from './algo/AlgoBlock'
export * from './algo/AlgoTx'
6 changes: 3 additions & 3 deletions src/transaction/algo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { signAlgoTransaction } from './algo'
import { sendAlgoSignedTransaction } from './algo'
import { AlgoTransaction } from '../model';

describe('Algo transaction', () => {
Expand All @@ -11,7 +11,7 @@ describe('Algo transaction', () => {
tx.amount = '1000000';
tx.note = 'Helloworld';
tx.fromPrivateKey = '72TCV5BRQPBMSAFPYO3CPWVDBYWNGAYNMTW5QHENOMQF7I6QLNMJWCJZ7A3V5YKD7QD6ZZPEHG2PV2ZVVEDDO6BCRGXWIL3DIUMSUCI';
const txId = await signAlgoTransaction(true,tx, 'https://testnet-algorand.api.purestake.io/ps2');
expect(txId.length).toBe(52)
const txId = String(await sendAlgoSignedTransaction(true,tx, 'https://testnet-algorand.api.purestake.io/ps2'));
expect(txId.length).toBe(52);
})
})
Loading

0 comments on commit 5982b2f

Please sign in to comment.