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 all 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"
}
}
20 changes: 17 additions & 3 deletions node/coinstacks/solana/api/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ import {
InternalServerError,
SendTxBody,
ValidationError,
handleError,
} from '../../../common/api/src' // unable to import models from a module with tsoa
import { Account, TxHistory } from './models'
import { Helius } from 'helius-sdk'

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 logger = new Logger({
namespace: ['unchained', 'coinstacks', 'solana', 'api'],
level: process.env.LOG_LEVEL,
})

const heliusSdk = new Helius(RPC_API_KEY)

@Route('api/v1')
@Tags('v1')
export class Solana implements BaseAPI {
Expand Down Expand Up @@ -78,8 +87,13 @@ 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> {
return ''
async sendTx(@Body() body: SendTxBody): Promise<string> {
try {
const txSig = await heliusSdk.connection.sendRawTransaction(Buffer.from(body.hex, 'base64'))

return txSig
} catch (err) {
throw handleError(err)
}
}
}
4 changes: 3 additions & 1 deletion node/coinstacks/solana/api/src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@
"security": [],
"parameters": [],
"requestBody": {
"description": "serialized raw transaction hex",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendTxBody"
"$ref": "#/components/schemas/SendTxBody",
"description": "serialized raw transaction hex"
}
}
}
Expand Down
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