refactored
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
import { GetSolBalance, GetTicketsAccount, GetTicketsBalanceByTA, GetTokenAccount, GetTokenBalanceByTA } from "./sol";
|
import { GetSolBalance, GetTicketsAccount, GetTicketsBalanceByTA, GetTokenAccount, GetTokenBalanceByTA } from "./sol/reader";
|
||||||
|
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|||||||
0
src/sol/operator.ts
Normal file
0
src/sol/operator.ts
Normal file
@@ -1,25 +1,19 @@
|
|||||||
import { PublicKey, Connection } from '@solana/web3.js';
|
import { PublicKey, Connection } from '@solana/web3.js';
|
||||||
|
import {connection, TICKETS_MINT, TOKENS_MINT} from './shared';
|
||||||
const TOKENS_MINT = new PublicKey('vcHyeKhk67CVumjzYV3m8cf6V8xcE85N9ay48pcyUpB');
|
|
||||||
const TICKETS_MINT = new PublicKey('tktUDLZhFGb9VW9zDxZ7HYDFuBooEf8daZEvPbBY7at');
|
|
||||||
|
|
||||||
const solana = new Connection("https://api.devnet.solana.com")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function GetSolBalance(wallet){
|
export async function GetSolBalance(wallet){
|
||||||
const balance = await solana.getBalance(new PublicKey(wallet));
|
const balance = await connection.getBalance(new PublicKey(wallet));
|
||||||
|
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function GetTokenAccount(ownerAddress){
|
export async function GetTokenAccount(ownerAddress){
|
||||||
const accountPublicKey = new PublicKey(ownerAddress);
|
const accountPublicKey = new PublicKey(ownerAddress);
|
||||||
const account = await solana.getTokenAccountsByOwner(accountPublicKey, {mint: TOKENS_MINT});
|
const account = await connection.getTokenAccountsByOwner(accountPublicKey, {mint: TOKENS_MINT});
|
||||||
try{
|
try{
|
||||||
const tokenAddress = account.value[0].pubkey.toString();
|
const tokenAddress = account.value[0].pubkey.toString();
|
||||||
return tokenAddress;
|
return tokenAddress;
|
||||||
@@ -42,11 +36,11 @@ export async function GetTokenBalanceByTA(tokenAccountAddress){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const tokenAccount = new PublicKey(tokenAccountAddress);
|
const tokenAccount = new PublicKey(tokenAccountAddress);
|
||||||
const info = await solana.getTokenAccountBalance(tokenAccount);
|
const info = await connection.getTokenAccountBalance(tokenAccount);
|
||||||
if (info.value.uiAmount == null){
|
if (info.value.uiAmount == null){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
console.log('Token Balance (using Solana-Web3.js): ', info.value.uiAmount);
|
console.log('Token Balance (using connection-Web3.js): ', info.value.uiAmount);
|
||||||
return info.value.uiAmount;
|
return info.value.uiAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +49,7 @@ export async function GetTokenBalanceByTA(tokenAccountAddress){
|
|||||||
|
|
||||||
export async function GetTicketsAccount(ownerAddress){
|
export async function GetTicketsAccount(ownerAddress){
|
||||||
const accountPublicKey = new PublicKey(ownerAddress);
|
const accountPublicKey = new PublicKey(ownerAddress);
|
||||||
const account = await solana.getTokenAccountsByOwner(accountPublicKey, {mint: TICKETS_MINT});
|
const account = await connection.getTokenAccountsByOwner(accountPublicKey, {mint: TICKETS_MINT});
|
||||||
|
|
||||||
try{
|
try{
|
||||||
const tokenAddress = account.value[0].pubkey.toString();
|
const tokenAddress = account.value[0].pubkey.toString();
|
||||||
@@ -79,7 +73,7 @@ export async function GetTicketsBalanceByTA(tokenAccountAddress){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const tokenAccount = new PublicKey(tokenAccountAddress);
|
const tokenAccount = new PublicKey(tokenAccountAddress);
|
||||||
const info = await solana.getTokenAccountBalance(tokenAccount);
|
const info = await connection.getTokenAccountBalance(tokenAccount);
|
||||||
if (info.value.uiAmount == null){
|
if (info.value.uiAmount == null){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
6
src/sol/shared.ts
Normal file
6
src/sol/shared.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { Connection, PublicKey } from "@solana/web3.js";
|
||||||
|
|
||||||
|
export const TOKENS_MINT = new PublicKey('vcHyeKhk67CVumjzYV3m8cf6V8xcE85N9ay48pcyUpB');
|
||||||
|
export const TICKETS_MINT = new PublicKey('tktUDLZhFGb9VW9zDxZ7HYDFuBooEf8daZEvPbBY7at');
|
||||||
|
|
||||||
|
export const connection = new Connection("https://api.devnet.solana.com")
|
||||||
Reference in New Issue
Block a user