Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solana send endpoint #1049

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion node/coinstacks/solana/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@shapeshiftoss/common-api": "^10.0.0",
"@solana/web3.js": "^2.0.0-rc.1"
"@solana/web3.js": "^2.0.0-rc.1",
"helius-sdk": "^1.3.5"
}
}
18 changes: 16 additions & 2 deletions node/coinstacks/solana/api/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import {
ValidationError,
} from '../../../common/api/src' // unable to import models from a module with tsoa
import { Account, TxHistory } from './models'
import { Service } from './service'

const RPC_URL = process.env.RPC_URL
const RPC_API_KEY = process.env.RPC_API_KEY

const NETWORK = process.env.NETWORK

if (!NETWORK) throw new Error('NETWORK env var not set')
if (!RPC_URL) throw new Error('RPC_URL env var not set')
if (!RPC_API_KEY) throw new Error('RPC_API_KEY env var not set')

export const service = new Service({
rpcUrl: RPC_URL,
rpcApiKey: RPC_API_KEY,
})

export const logger = new Logger({
namespace: ['unchained', 'coinstacks', 'solana', 'api'],
Expand All @@ -22,6 +33,8 @@ export const logger = new Logger({
@Route('api/v1')
@Tags('v1')
export class Solana implements BaseAPI {
static service: Service

/**
* Get information about the running coinstack
*
Expand Down Expand Up @@ -78,8 +91,9 @@ export class Solana implements BaseAPI {
@Response<ValidationError>(422, 'Validation Error')
@Response<InternalServerError>(500, 'Internal Server Error')
@Post('send/')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async sendTx(@Body() _body: SendTxBody): Promise<string> {
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved
return ''
return Solana.service.sendTx(_body)
}
}

Solana.service = service
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 38 additions & 0 deletions node/coinstacks/solana/api/src/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Account, API, Tx, TxHistory } from './models'
import { BaseAPI, handleError, SendTxBody } from '@shapeshiftoss/common-api'
import { Helius } from "helius-sdk";

export interface ServiceArgs {
rpcUrl: string
rpcApiKey: string
}

export class Service implements Omit<BaseAPI, 'getInfo'>, API {
private readonly heliusSdk: Helius

constructor(args: ServiceArgs) {
this.heliusSdk = new Helius(args.rpcApiKey)
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved
}

async getTransaction(): Promise<Tx> {
throw new Error('Method not implemented.')
}

async getAccount(): Promise<Account> {
throw new Error('Method not implemented.')
}

async getTxHistory(): Promise<TxHistory> {
throw new Error('Method not implemented.')
}

async sendTx(body: SendTxBody): Promise<string> {
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved
try {
const txSig = await this.heliusSdk.connection.sendRawTransaction(Buffer.from(body.hex, 'base64'));

return txSig
} catch (err) {
throw handleError(err)
}
}
}
2 changes: 1 addition & 1 deletion node/coinstacks/solana/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RPC_API_KEY=
INDEXER_URL=https://api.helius.xyz
LOG_LEVEL=debug
NETWORK=mainnet
RPC_URL=https://mainnet.helius-rpc.com
RPC_URL=https://mainnet.helius-rpc.com
Loading