Skip to content

Commit 9d20e8f

Browse files
committed
Inital commit
0 parents  commit 9d20e8f

File tree

8 files changed

+4374
-0
lines changed

8 files changed

+4374
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
tags: ['v*']
7+
pull_request:
8+
branches: [main, master]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
DEFAULT_BRANCH: main
14+
15+
concurrency:
16+
group: build-push-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build-and-push:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to Container Registry
34+
if: github.event_name == 'push' && github.ref != 'refs/tags/*'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract metadata
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=sha,prefix=sha-
52+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/' + env.DEFAULT_BRANCH }}
53+
54+
- name: Build Docker image
55+
uses: docker/build-push-action@v5
56+
id: build
57+
with:
58+
context: .
59+
platforms: linux/amd64,linux/arm64
60+
push: false
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
65+
66+
- name: Test Docker image
67+
run: |
68+
# Pull and run your container tests here, adjust as needed
69+
for tag in ${{ steps.meta.outputs.tags }}; do
70+
docker run --rm $tag echo "Test run successful for $tag"
71+
done
72+
73+
- name: Push Docker image
74+
if: github.event_name != 'pull_request'
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: .
78+
push: true
79+
tags: ${{ steps.meta.outputs.tags }}

index.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const TopupService = require('./src/topup-service');
2+
const NotificationService = require('./src/notification');
3+
const { ParameterParser, Logger, TelegramHelper } = require('./src/utils');
4+
5+
async function main() {
6+
try {
7+
// Parse arguments
8+
const args = process.argv.slice(2);
9+
10+
// Special command to get chat ID
11+
if (args.includes('--get-chat-id')) {
12+
const tokenIndex = args.indexOf('--telegram-bot-token');
13+
if (tokenIndex === -1 || !args[tokenIndex + 1]) {
14+
Logger.error('--telegram-bot-token is required with --get-chat-id');
15+
process.exit(1);
16+
}
17+
18+
const botToken = args[tokenIndex + 1];
19+
await TelegramHelper.getChatId(botToken);
20+
process.exit(0);
21+
}
22+
23+
const params = ParameterParser.extractParameters(args);
24+
25+
if (!params.success) {
26+
if (params.errors) {
27+
params.errors.forEach(error => Logger.error(error));
28+
}
29+
ParameterParser.showUsage();
30+
process.exit(1);
31+
}
32+
33+
// Initialize services
34+
const topupService = new TopupService();
35+
const notificationService = new NotificationService();
36+
37+
if (params.telegramEnabled) {
38+
notificationService.initialize(params.telegramBotToken, params.telegramUsername);
39+
}
40+
41+
// Execute topup
42+
Logger.info(`Starting ARIO top-up: ${params.amount} from ${params.walletPath}`);
43+
const result = await topupService.executeTopup(params.walletPath, params.amount);
44+
45+
// Log success
46+
Logger.success(`Top-up completed! Status: ${result.status}, TX: ${result.transactionId}`);
47+
Logger.info(`Used: ${result.topupAmount} ARIO, Remaining: ${result.remainingBalance.toFixed(6)} ARIO`);
48+
49+
// Send notification
50+
if (params.telegramEnabled) {
51+
await notificationService.notifySuccess(
52+
result.publicKey,
53+
result.topupAmount,
54+
result.status,
55+
result.transactionId,
56+
result.remainingBalance
57+
);
58+
}
59+
60+
} catch (error) {
61+
Logger.error(`Failed: ${error.message}`);
62+
63+
// Send error notification if telegram is enabled
64+
const args = process.argv.slice(2);
65+
const params = ParameterParser.extractParameters(args);
66+
67+
if (params.success && params.telegramEnabled) {
68+
const notificationService = new NotificationService();
69+
await notificationService.initialize(params.telegramBotToken, params.telegramUsername);
70+
71+
const publicKey = params.walletPath ?
72+
require('path').basename(params.walletPath, '.json') : 'Unknown';
73+
74+
await notificationService.notifyError(publicKey, error.message, params.amount);
75+
}
76+
77+
process.exit(1);
78+
}
79+
}
80+
81+
main();

0 commit comments

Comments
 (0)