Skip to content

Commit 564ec58

Browse files
Merge pull request #33 from GalaxySciTech/cursor/-bc-bf273b18-c720-4b11-8652-4039166c2aad-88b6
Deep optimization: modernize build, fix code quality, add tests, improve CI/CD
2 parents e7bbc3b + 7053091 commit 564ec58

26 files changed

Lines changed: 1127 additions & 164 deletions

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
java: [ '8', '11', '17' ]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up JDK ${{ matrix.java }}
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: ${{ matrix.java }}
26+
distribution: 'temurin'
27+
28+
- name: Setup Gradle
29+
uses: gradle/actions/setup-gradle@v3
30+
31+
- name: Grant execute permission for gradlew
32+
run: chmod +x gradlew
33+
34+
- name: Build
35+
run: ./gradlew build
36+
37+
- name: Run tests
38+
run: ./gradlew test
39+
40+
- name: Upload test results
41+
if: always()
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: test-results-java-${{ matrix.java }}
45+
path: build/reports/tests/test/
46+
retention-days: 7

.gitignore

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1+
# Gradle
12
.gradle/
23
build/
4+
/build
5+
/*/build/
6+
7+
# IDE
38
.settings/
49
.project
510
.classpath
6-
*.class
7-
.idea
11+
.idea/
812
*.iml
9-
/local.properties
10-
.DS_Store
11-
/build
13+
*.ipr
14+
*.iws
15+
.vscode/
16+
17+
# Compiled
18+
*.class
1219
/*/out/
13-
out
20+
out/
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db
25+
26+
# Properties
27+
/local.properties
28+
29+
# Test output
30+
bin/

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1 align="center">Tokencore</h1>
22

33
<p align="center">
4-
<a href="https://travis-ci.com/galaxyscitech/tokencore">
5-
<img src="https://travis-ci.com/galaxyscitech/tokencore.svg?branch=master" alt="Build Status">
4+
<a href="https://github.com/galaxyscitech/tokencore/actions">
5+
<img src="https://github.com/galaxyscitech/tokencore/actions/workflows/ci.yml/badge.svg" alt="Build Status">
66
</a>
77
<a href="https://github.com/galaxyscitech/tokencore/issues">
88
<img src="https://img.shields.io/github/issues/galaxyscitech/tokencore.svg" alt="Issues">
@@ -34,6 +34,11 @@ Tokencore is a central component for blockchain wallet backends. It currently su
3434
- TRX, TRC20, BCH, BSV
3535
- DOGE, DASH, LTC, FILECOIN
3636

37+
## Requirements
38+
39+
- Java 8+
40+
- Gradle 8.5+ (included via wrapper)
41+
3742
## Integration
3843

3944
### Gradle
@@ -43,36 +48,28 @@ repositories {
4348
maven { url 'https://jitpack.io' }
4449
}
4550
dependencies {
46-
compile 'com.github.galaxyscitech:tokencore:1.2.7'
51+
implementation 'com.github.galaxyscitech:tokencore:1.3.0'
4752
}
4853
```
4954

5055
### Maven
5156

5257
```xml
5358
<repositories>
54-
<repository>
55-
<id>tronj</id>
56-
<url>https://dl.bintray.com/tronj/tronj</url>
57-
</repository>
5859
<repository>
5960
<id>jitpack.io</id>
6061
<url>https://jitpack.io</url>
6162
</repository>
6263
</repositories>
6364

6465
<dependency>
65-
<groupId>com.github.galaxyzxcv</groupId>
66+
<groupId>com.github.galaxyscitech</groupId>
6667
<artifactId>tokencore</artifactId>
67-
<version>1.2.7</version>
68+
<version>1.3.0</version>
6869
</dependency>
6970
```
7071

71-
## Sample Test
72-
73-
View a sample test at [Tokencore Test Sample](https://github.com/galaxyscitech/tokencore/blob/master/src/test/java/org/consenlabs/tokencore/Test.java).
74-
75-
## Usage Guide
72+
## Quick Start
7673

7774
### Initialize Identity
7875

@@ -81,12 +78,17 @@ try {
8178
Files.createDirectories(Paths.get("${keyStoreProperties.dir}/wallets"));
8279
} catch(Throwable ignored) {}
8380

84-
WalletManager.storage = new KeystoreStorage();
81+
WalletManager.storage = new KeystoreStorage() {
82+
@Override
83+
public File getKeystoreDir() {
84+
return new File("/path/to/keystore");
85+
}
86+
};
8587
WalletManager.scanWallets();
86-
String password = "123456";
88+
String password = "your_password";
8789
Identity identity = Identity.getCurrentIdentity();
8890

89-
if(identity == null) {
91+
if (identity == null) {
9092
Identity.createIdentity("token", password, "", Network.MAINNET, Metadata.P2WPKH);
9193
}
9294
```
@@ -95,23 +97,22 @@ if(identity == null) {
9597

9698
```java
9799
Identity identity = Identity.getCurrentIdentity();
98-
String password = "123456";
99-
Wallet wallet = identity.deriveWalletByMnemonics(ChainType.BITCOIN, password, MnemonicUtil.randomMnemonicCodes());
100+
String password = "your_password";
101+
Wallet wallet = identity.deriveWalletByMnemonics(
102+
ChainType.BITCOIN, password, MnemonicUtil.randomMnemonicCodes());
100103
System.out.println(wallet.getAddress());
101104
```
102105

103106
## Offline Signature
104107

105-
Offline signing refers to the process of creating a digital signature for a transaction without connecting to the internet. This method enhances security by ensuring private keys never come in contact with an online environment. Here's how you can create an offline signature with Tokencore for Bitcoin and TRON:
108+
Offline signing refers to the process of creating a digital signature for a transaction without connecting to the internet. This method enhances security by ensuring private keys never come in contact with an online environment.
106109

107110
### Bitcoin
108111

109112
1. **Set Up Transaction Details**
110113

111-
Define the details of your Bitcoin transaction, including recipient's address, change index, amount to be transferred, and the fee.
112-
113114
```java
114-
String password = "123456";
115+
String password = "your_password";
115116
String toAddress = "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9";
116117
int changeIdx = 0;
117118
long amount = 1000L;
@@ -128,39 +129,67 @@ Offline signing refers to the process of creating a digital signature for a tran
128129

129130
3. **Initialize Transaction & Sign**
130131

131-
With all the details in place, initialize the Bitcoin transaction and sign it offline.
132-
133132
```java
134-
BitcoinTransaction bitcoinTransaction = new BitcoinTransaction(toAddress, changeIdx, amount, fee, utxos);
135-
Wallet wallet = WalletManager.findWalletByAddress(ChainType.BITCOIN, "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9");
136-
TxSignResult txSignResult = bitcoinTransaction.signTransaction(String.valueOf(ChainId.BITCOIN_MAINNET), password, wallet);
137-
System.out.println(txSignResult);
133+
BitcoinTransaction bitcoinTransaction = new BitcoinTransaction(
134+
toAddress, changeIdx, amount, fee, utxos);
135+
Wallet wallet = WalletManager.findWalletByAddress(
136+
ChainType.BITCOIN, "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9");
137+
TxSignResult txSignResult = bitcoinTransaction.signTransaction(
138+
String.valueOf(ChainId.BITCOIN_MAINNET), password, wallet);
139+
System.out.println(txSignResult.getSignedTx());
138140
```
139141

140142
### TRON
141143

142144
1. **Set Up Transaction Details**
143145

144-
Define your TRON transaction details, including the sender's address, recipient's address, and amount.
145-
146146
```java
147147
String from = "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8";
148148
String to = "TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3";
149149
long amount = 1;
150-
String password = "123456";
150+
String password = "your_password";
151151
```
152152

153153
2. **Initialize Transaction & Sign**
154154

155-
Once you have the transaction details, initialize the TRON transaction and sign it offline.
156-
157155
```java
158156
TronTransaction transaction = new TronTransaction(from, to, amount);
159-
Wallet wallet = WalletManager.findWalletByAddress(ChainType.BITCOIN, "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8");
160-
TxSignResult txSignResult = transaction.signTransaction(String.valueOf(ChainId.BITCOIN_MAINNET), password, wallet);
161-
System.out.println(txSignResult);
157+
Wallet wallet = WalletManager.findWalletByAddress(
158+
ChainType.TRON, "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8");
159+
TxSignResult txSignResult = transaction.signTransaction(
160+
"mainnet", password, wallet);
161+
System.out.println(txSignResult.getSignedTx());
162162
```
163163

164-
Remember, offline signing enhances security but requires a thorough understanding of transaction construction to avoid errors.
164+
### Ethereum
165+
166+
```java
167+
EthereumTransaction tx = new EthereumTransaction(
168+
BigInteger.ZERO, // nonce
169+
BigInteger.valueOf(20_000_000_000L), // gasPrice
170+
BigInteger.valueOf(21000), // gasLimit
171+
"0xRecipientAddress", // to
172+
BigInteger.valueOf(1_000_000_000_000_000_000L), // value (1 ETH)
173+
"" // data
174+
);
175+
176+
Wallet wallet = WalletManager.findWalletByAddress(
177+
ChainType.ETHEREUM, "0xYourAddress");
178+
TxSignResult result = tx.signTransaction(
179+
String.valueOf(ChainId.ETHEREUM_MAINNET), password, wallet);
180+
System.out.println(result.getSignedTx());
181+
```
182+
183+
## Running Tests
184+
185+
```bash
186+
./gradlew test
187+
```
188+
189+
## Building
190+
191+
```bash
192+
./gradlew build
193+
```
165194

166195
> **Note**: Tokencore is a functional component for digital currency. It's primarily for learning purposes and doesn't offer a complete blockchain business suite.

0 commit comments

Comments
 (0)