Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create url
Browse files Browse the repository at this point in the history
sebastijankuzner committed Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b84a6fb commit 4686dd5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/api-evm/source/actions/eth-send-raw-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, injectable } from "@mainsail/container";
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
import { Constants, Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
import { Environment } from "@mainsail/kernel";
import { http } from "@mainsail/utils";

@injectable()
@@ -19,7 +20,7 @@ export class EthSendRawTransactionAction implements Contracts.Api.RPC.Action {
};

public async handle(parameters: [string]): Promise<string> {
const response = await http.post("http://localhost:4007/api/transactions", {
const response = await http.post(this.#getUrl(), {
body: { transactions: [parameters[0].slice(2)] },
});

@@ -35,4 +36,29 @@ export class EthSendRawTransactionAction implements Contracts.Api.RPC.Action {
// TODO Improve error handling
throw new Exceptions.RpcError("Error sending transaction");
}

#getUrl(): string {
const config = {
http: {
enabled: !Environment.isTrue(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_DISABLED),
host: Environment.get(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_HOST, "0.0.0.0"),
port: Environment.get(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_PORT, 4007),
},
https: {
enabled: Environment.isTrue(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_SSL),
host: Environment.get(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_SSL_HOST, "0.0.0.0"),
port: Environment.get(Constants.EnvironmentVariables.CORE_API_TRANSACTION_POOL_SSL_PORT, 8447),
},
};

if (config.http.enabled) {
return `http://${config.http.host}:${config.http.port}/api/transactions`;
}

if (config.https.enabled) {
return `https://${config.https.host}:${config.https.port}/api/transactions`;
}

throw new Error("Server is not enabled");
}
}

0 comments on commit 4686dd5

Please sign in to comment.