├── docs ├── img │ ├── RandomX_two.png │ ├── RandomX_first.png │ ├── RandomX_three.png │ ├── xdag │ │ ├── XDAG_eighth.png │ │ ├── XDAG_fifth.png │ │ ├── XDAG_first.png │ │ ├── XDAG_fourth.png │ │ ├── XDAG_ninth.png │ │ ├── XDAG_second.png │ │ ├── XDAG_sixth.png │ │ ├── XDAG_tenth.png │ │ ├── XDAG_third.png │ │ ├── XDAG_eleventh.png │ │ ├── XDAG_fifteenth.png │ │ ├── XDAG_seventh.png │ │ ├── XDAG_sixteenth.png │ │ ├── XDAG_twelfth.png │ │ ├── XDAG_eighteenth.png │ │ ├── XDAG_fourteenth.png │ │ ├── XDAG_seventeenth.png │ │ └── XDAG_thirteenth.png │ ├── C_version_snapshot.png │ └── Open_the_security_group.png ├── XDAGJ_SNAPSHOT_zh.md ├── XDAGJ_Message_Encoding_en.md ├── XDAGJ_Time_Synchronization_zh.md ├── XDAGJ_Time_Synchronization_en.md ├── Win10_Configuration_RandomX_Algorithm_Environment_zh.md ├── XDAGJ_RPC_Service_Tutorial_en.md ├── Win10_Configuration_RandomX_Algorithm_Environment_en.md └── XDAGJ_Network_Protocol_en.md ├── src ├── main │ ├── resources │ │ ├── lombok.config │ │ ├── xdag-devnet.conf │ │ ├── druid.properties │ │ ├── xdag-testnet.conf │ │ └── xdag-mainnet.conf │ └── java │ │ └── io │ │ └── xdag │ │ ├── listener │ │ ├── Listener.java │ │ ├── Message.java │ │ ├── PretopMessage.java │ │ └── BlockMessage.java │ │ ├── db │ │ ├── rocksdb │ │ │ ├── DatabaseFactory.java │ │ │ ├── DatabaseName.java │ │ │ ├── KVSource.java │ │ │ └── RocksdbFactory.java │ │ ├── execption │ │ │ ├── SerializationException.java │ │ │ ├── DeserializationException.java │ │ │ └── SerDeException.java │ │ ├── TransactionHistoryStore.java │ │ ├── OrphanBlockStore.java │ │ ├── SnapshotStore.java │ │ └── AddressStore.java │ │ ├── pool │ │ └── PoolAwardManager.java │ │ ├── net │ │ ├── message │ │ │ ├── consensus │ │ │ │ ├── BlockExtRequestMessage.java │ │ │ │ ├── BlockExtReplyMessage.java │ │ │ │ ├── BlocksReplyMessage.java │ │ │ │ ├── BlocksRequestMessage.java │ │ │ │ ├── SumRequestMessage.java │ │ │ │ ├── BlockRequestMessage.java │ │ │ │ ├── SyncBlockRequestMessage.java │ │ │ │ ├── SumReplyMessage.java │ │ │ │ ├── NewBlockMessage.java │ │ │ │ └── SyncBlockMessage.java │ │ │ ├── MessageException.java │ │ │ ├── Message.java │ │ │ └── p2p │ │ │ │ ├── PongMessage.java │ │ │ │ ├── PingMessage.java │ │ │ │ ├── DisconnectMessage.java │ │ │ │ └── InitMessage.java │ │ ├── Capability.java │ │ ├── node │ │ │ └── Node.java │ │ └── NetDBManager.java │ │ ├── rpc │ │ ├── model │ │ │ ├── response │ │ │ │ ├── NetConnResponse.java │ │ │ │ ├── ProcessResponse.java │ │ │ │ ├── XdagStatusResponse.java │ │ │ │ ├── ConfigResponse.java │ │ │ │ └── BlockResponse.java │ │ │ └── request │ │ │ │ └── TransactionRequest.java │ │ └── server │ │ │ ├── handler │ │ │ └── JsonRpcRequestHandler.java │ │ │ └── protocol │ │ │ ├── JsonRpcErrorResponse.java │ │ │ ├── JsonRpcResponse.java │ │ │ └── JsonRpcRequest.java │ │ ├── config │ │ ├── spec │ │ │ ├── RandomxSpec.java │ │ │ ├── WalletSpec.java │ │ │ ├── FundSpec.java │ │ │ ├── AdminSpec.java │ │ │ └── RPCSpec.java │ │ ├── RandomXConstants.java │ │ ├── MainnetConfig.java │ │ ├── TestnetConfig.java │ │ └── DevnetConfig.java │ │ ├── consensus │ │ └── PoW.java │ │ ├── Bootstrap.java │ │ ├── core │ │ ├── XdagLifecycle.java │ │ ├── XdagTopStatus.java │ │ ├── BlockState.java │ │ ├── BlockType.java │ │ ├── XdagExtStats.java │ │ ├── XUnit.java │ │ ├── PreBlockInfo.java │ │ ├── AbstractXdagLifecycle.java │ │ ├── SnapshotInfo.java │ │ └── ImportResult.java │ │ ├── crypto │ │ └── RandomXMemory.java │ │ └── utils │ │ └── FileUtils.java ├── test │ ├── resources │ │ ├── druid.properties │ │ └── xdag-devnet.conf │ └── java │ │ └── io │ │ └── xdag │ │ ├── cli │ │ ├── ShellTest.java │ │ └── TelnetServerTest.java │ │ ├── consensus │ │ └── XdagNatServiceConfigurationPowTest.java │ │ ├── crypto │ │ └── WalletTest.java │ │ ├── LauncherTest.java │ │ ├── net │ │ ├── message │ │ │ ├── MessageFactoryTest.java │ │ │ ├── ReasonCodeTest.java │ │ │ ├── MessageCodeTest.java │ │ │ └── p2p │ │ │ │ └── InitMessageTest.java │ │ ├── CapabilityTest.java │ │ ├── NodeManagerTest.java │ │ ├── FrameTest.java │ │ └── ChannelManagerTest.java │ │ ├── config │ │ ├── ConstantsTest.java │ │ ├── MainnetConfigTest.java │ │ ├── TestnetConfigTest.java │ │ └── DevnetConfigTest.java │ │ ├── utils │ │ ├── XdagNatServiceConfigurationTimeTest.java │ │ └── BytesTest.java │ │ └── core │ │ └── MintTest.java └── assembly │ └── distribution.xml ├── .vscode └── settings.json ├── .github ├── ISSUE_TEMPLATE │ ├── doc-request.md │ ├── feature_request.md │ ├── refactor-request.md │ └── bug_report.md └── workflows │ └── maven.yml ├── .gitignore ├── script ├── mysql_create_table.sql ├── xdag.bat └── xdag.sh ├── misc ├── systemd │ └── xdagj.service └── code-style │ └── formatter_intellij.xml └── LICENSE /docs/img/RandomX_two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/RandomX_two.png -------------------------------------------------------------------------------- /docs/img/RandomX_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/RandomX_first.png -------------------------------------------------------------------------------- /docs/img/RandomX_three.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/RandomX_three.png -------------------------------------------------------------------------------- /src/main/resources/lombok.config: -------------------------------------------------------------------------------- 1 | config.stopBubbling=true 2 | lombok.equalsAndHashCode.callSuper=call -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_eighth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_eighth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_fifth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_fifth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_first.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_fourth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_fourth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_ninth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_ninth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_second.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_second.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_sixth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_sixth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_tenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_tenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_third.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_third.png -------------------------------------------------------------------------------- /docs/img/C_version_snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/C_version_snapshot.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_eleventh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_eleventh.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_fifteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_fifteenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_seventh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_seventh.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_sixteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_sixteenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_twelfth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_twelfth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_eighteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_eighteenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_fourteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_fourteenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_seventeenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_seventeenth.png -------------------------------------------------------------------------------- /docs/img/xdag/XDAG_thirteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/xdag/XDAG_thirteenth.png -------------------------------------------------------------------------------- /docs/img/Open_the_security_group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XDagger/xdagj/HEAD/docs/img/Open_the_security_group.png -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.compile.nullAnalysis.mode": "automatic", 3 | "java.configuration.updateBuildConfiguration": "interactive" 4 | } -------------------------------------------------------------------------------- /src/test/resources/druid.properties: -------------------------------------------------------------------------------- 1 | driverClassName=org.h2.Driver 2 | url=jdbc:h2:mem:xdagj;MODE=MYSQL;DB_CLOSE_DELAY=-1 3 | username=xdagj 4 | password=xdagj 5 | initialSize=5 6 | maxActive=10 7 | maxWait=3000 8 | testWhileIdle=false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/doc-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Doc request 3 | about: Document update request 4 | title: DOC 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | Please tell us what kind of document you need. 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #for eclipse 2 | /target/ 3 | .classpath 4 | .project 5 | /.settings/ 6 | /bin/ 7 | 8 | #for idea 9 | xdagj.iml 10 | .idea 11 | logs 12 | 13 | de 14 | #for project 15 | devnet 16 | xdagj.jar 17 | testnet 18 | mainnet 19 | target 20 | logs 21 | dist 22 | #for macos 23 | .DS_Store 24 | src/c/ 25 | src/main/resources/native 26 | src/main/resources/xdag-mainnet.conf 27 | dependency-reduced-pom.xml 28 | pool -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Add more interesting features to XDAGJ 4 | title: 'Feature : ' 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the new features you want to add* 11 | Describe in detail the interesting features you want to achieve.[eg. Hope that XDAGJ will join the virtual machine function so that we can customize our own smart contract] 12 | -------------------------------------------------------------------------------- /src/test/resources/xdag-devnet.conf: -------------------------------------------------------------------------------- 1 | # Admin Config 2 | admin.telnet.ip = 127.0.0.1 3 | admin.telnet.port = 6001 4 | admin.telnet.password = root 5 | 6 | # Node Config 7 | node.ip = 127.0.0.1 8 | node.port = 8001 9 | node.maxInboundConnectionsPerIp = 8 10 | node.whiteIPs = ["127.0.0.1:8001","127.0.0.1:8002"] 11 | 12 | node.transaction.history.pageSizeLimit = 888 13 | 14 | # Node RPC Config 15 | rpc.enabled = true 16 | rpc.http.host = 127.0.0.1 17 | rpc.http.port = 10001 18 | rpc.ws.port = 10002 -------------------------------------------------------------------------------- /script/mysql_create_table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `t_transaction_history` ( 2 | `fid` int NOT NULL AUTO_INCREMENT, 3 | `faddress` varchar(64) NOT NULL, 4 | `faddresstype` tinyint NOT NULL, 5 | `fhash` varchar(64) NOT NULL, 6 | `famount` decimal(20,9) unsigned zerofill NOT NULL, 7 | `ftype` tinyint NOT NULL, 8 | `fremark` varchar(64) DEFAULT NULL, 9 | `ftime` datetime(3) NOT NULL, 10 | PRIMARY KEY (`fid`), 11 | UNIQUE KEY `id_UNIQUE` (`fid`), 12 | KEY `faddress_index` (`faddress`) 13 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci -------------------------------------------------------------------------------- /docs/XDAGJ_SNAPSHOT_zh.md: -------------------------------------------------------------------------------- 1 | ### XDAGJ snapshot loading method 2 | 3 | 4 | 1. import the wallet of the c pool 5 | ```shell script 6 | ./xdag.sh --convertoldwallet /wallet-testnet.dat -t 7 | ``` 8 | 2. prepare to load snapshot 9 | ```shell script 10 | ./xdag.sh --loadsnapshot -t 11 | ``` 12 | 3. load snapshot (snapshot time in hex) 13 | ```shell script 14 | ./xdag.sh -t --enablesnapshot 15 | ``` 16 | 17 | 18 | ![C version snapshot](img/C_version_snapshot.png) 19 | -------------------------------------------------------------------------------- /docs/XDAGJ_Message_Encoding_en.md: -------------------------------------------------------------------------------- 1 | # Message Encoding 2 | Xdagj network messages format. 3 | 4 | ## Types 5 | 6 | ### boolean 7 | 1 bit 8 | 9 | ### long 10 | 8 bytes 11 | 12 | ### int 13 | 4 bytes 14 | 15 | ### byte[] 16 | First write the number of bytes using [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity), then write each byte. 17 | 18 | ### string 19 | First write the number of bytes using [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity), then write each byte of the string. 20 | 21 | ## VLQ 22 | Variable length quantity. This encoding allows for writing both large and small numbers in an efficient manner. -------------------------------------------------------------------------------- /docs/XDAGJ_Time_Synchronization_zh.md: -------------------------------------------------------------------------------- 1 | ### XDAGJ 配置时间同步 2 | 3 | ------ 4 | 5 | #### Linux(Ubuntu) 6 | 7 | ##### 1.下载 ntp 8 | 9 | ``` 10 | sudo apt install ntp ntpdate 11 | ``` 12 | 13 | ##### 2. 关闭ntp服务并取消开机启动 14 | 15 | ``` 16 | systemctl stop ntp 17 | sudo systemctl disable ntp 18 | ``` 19 | 20 | ##### 3. 开启定时任务同步 21 | 22 | ``` 23 | sudo crontab -e 24 | ``` 25 | 26 | 输入以下语句并保存: 27 | 28 | ``` 29 | */5 * * * * /usr/sbin/ntpdate time.nist.gov 30 | ``` 31 | 32 | ##### 4. 将系统时间写入到主板 33 | 34 | ``` 35 | sudo hwclock -w 36 | ``` 37 | 38 | ##### 5. 验证 39 | 40 | 修改本机时间,5分钟后会自动同步正确的时间。 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/refactor-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Refactor request 3 | about: Refactor and optimize the code 4 | title: 'Refactor : ' 5 | labels: refactor 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Problem Description** 11 | Describe the problematic code snippet as clearly as possible. 12 | [eg. The processing logic of existing miners is more cumbersome and can be handled in a more elegant way] 13 | [eg. Line xx to line xx of the code in xx.java may have another thread crash vulnerability, which needs to be fixed as soon as possible] 14 | 15 | **Suggestion(option)** 16 | If you have a good modification method, you can explain it here, or submit a pull request. 17 | -------------------------------------------------------------------------------- /src/main/resources/xdag-devnet.conf: -------------------------------------------------------------------------------- 1 | # Admin Config 2 | admin.telnet.ip = 127.0.0.1 3 | admin.telnet.port = 6001 4 | admin.telnet.password = root 5 | 6 | # Pool Config 7 | pool.ws.port = 7001 8 | 9 | # Node config 10 | node.ip = 127.0.0.1 11 | node.port = 8001 12 | node.tag = xdagj-node-1 13 | node.maxInboundConnectionsPerIp = 8 14 | node.whiteIPs = ["127.0.0.1:8001","127.0.0.1:8002"] 15 | node.generate.block.enable = true 16 | 17 | # Node transaction history config 18 | node.transaction.history.enable = false 19 | 20 | # Node RPC Config 21 | rpc.http.enabled = true 22 | rpc.http.host = 127.0.0.1 23 | rpc.http.port = 10001 24 | rpc.ws.port = 10002 25 | 26 | # Randomx Config 27 | randomx.flags.fullmem = false -------------------------------------------------------------------------------- /src/main/resources/druid.properties: -------------------------------------------------------------------------------- 1 | driverClassName=com.mysql.cj.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/xdagj?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&&serverTimezone=UTC 3 | username=xdagj 4 | password=xdagj 5 | minIdle=5 6 | initialSize=5 7 | maxActive=10 8 | maxWait=100 9 | testOnBorrow=true 10 | testOnReturn=true 11 | testWhileIdle=true 12 | validationQuery=select 1 13 | validationQueryTimeout=1 14 | timeBetweenEvictionRunsMillis=480000 15 | ConnectionErrorRetryAttempts=3 16 | NotFullTimeoutRetryCount=3 17 | #removeAbandonedTimeoutMillis=480000 18 | #removeAbandoned=true 19 | numTestsPerEvictionRun=3 20 | minEvictableIdleTimeMillis=480000 21 | maxEvictableIdleTimeMillis=600000 22 | keepAliveBetweenTimeMillis=540000 -------------------------------------------------------------------------------- /src/main/resources/xdag-testnet.conf: -------------------------------------------------------------------------------- 1 | # Admin Config 2 | admin.telnet.ip = 127.0.0.1 3 | admin.telnet.port = 6001 4 | admin.telnet.password = ADMIN_TELNET_PASSWORD 5 | 6 | # Pool Config 7 | pool.ip = 127.0.0.1 8 | pool.port = 7001 9 | pool.tag = XdagJ 10 | 11 | # Node config 12 | node.ip = 127.0.0.1 13 | node.port = 8001 14 | node.maxInboundConnectionsPerIp = 8 15 | node.whiteIPs = ["127.0.0.1:8001","127.0.0.1:8002"] 16 | node.generate.block.enable = true 17 | 18 | # Node transaction history config 19 | node.transaction.history.enable = true 20 | 21 | # Node RPC Config 22 | rpc.http.enabled = true 23 | rpc.http.host = 127.0.0.1 24 | rpc.http.port = 10001 25 | rpc.ws.port = 10002 26 | 27 | # Randomx Config 28 | randomx.flags.fullmem = false -------------------------------------------------------------------------------- /misc/systemd/xdagj.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Xdagj 3 | After=network.target 4 | 5 | [Service] 6 | User=xdagj 7 | Group=xdagj 8 | Type=simple 9 | Restart=on-failure 10 | 11 | # For Mainnet node 12 | # ExecStart=/usr/local/xdagj/xdag.sh 13 | 14 | # For Testnet node 15 | # ExecStart=/usr/local/xdagj/xdagj.sh -t 16 | 17 | # For Devtnet node(Default) 18 | ExecStart=/usr/local/xdagj/xdagj.sh -d 19 | 20 | # XDAGJ_WALLET_PASSWORD environment variable is required to automatically unlock your wallet.data file. 21 | # Please ensure sure that the access permission of this service unit file is properly configured when you put your password here. 22 | Environment=XDAGJ_WALLET_PASSWORD=YOUR_WALLET_PASSWORD 23 | 24 | [Install] 25 | WantedBy=multi-user.target 26 | -------------------------------------------------------------------------------- /script/xdag.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set XDAG_VERSION="${project.version}" 4 | set XDAG_JARNAME="xdagj-%XDAG_VERSION%-executable.jar" 5 | set XDAG_OPTS="-t" 6 | 7 | #set JAVA_HOME="C:\Program Files\Java\jdk" 8 | 9 | # default JVM options 10 | set JAVA_OPTS="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED -Xms4g -Xmx4g -XX:+ExitOnOutOfMemoryError -XX:+UseZGC" 11 | 12 | set JAVA_HEAPDUMP="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./logs/xdag-heapdump" 13 | 14 | set JAVA_GC_LOG="-Xlog:gc*,gc+heap=trace,gc+age=trace,safepoint:file=./logs/xdag-gc-%t.log:time,level,tid,tags:filecount=8,filesize=10m" 15 | 16 | set XDAGJ_VERSION="-Dxdagj.version=${XDAG_VERSION}" 17 | 18 | java %JAVA_OPTS% %JAVA_HEAPDUMP% %JAVA_GC_LOG% %XDAGJ_VERSION% -cp .;%XDAG_JARNAME% io.xdag.Bootstrap %* 19 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: maven ci 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | - develop 11 | pull_request: 12 | branches: 13 | - master 14 | - develop 15 | 16 | jobs: 17 | build: 18 | 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - name: Checkout code 23 | uses: actions/checkout@v4 24 | 25 | - name: Set up JDK 26 | uses: actions/setup-java@v4 27 | with: 28 | distribution: 'temurin' 29 | java-version: '21' 30 | cache: 'maven' 31 | 32 | - name: Build with Maven 33 | run: mvn clean package 34 | -------------------------------------------------------------------------------- /docs/XDAGJ_Time_Synchronization_en.md: -------------------------------------------------------------------------------- 1 | ### XDAGJ Configuration Time Synchronization 2 | 3 | ------ 4 | 5 | #### Linux(Ubuntu) 6 | 7 | ##### 1.Install ntp 8 | 9 | ``` 10 | sudo apt install ntp ntpdate 11 | ``` 12 | 13 | ##### 2. Stop the npt service and cancel the startup 14 | 15 | ``` 16 | systemctl stop ntp 17 | sudo systemctl disable ntp 18 | ``` 19 | 20 | ##### 3. Enable scheduled task synchronization 21 | 22 | ``` 23 | sudo crontab -e 24 | ``` 25 | 26 | Enter the following statement and save: 27 | 28 | ``` 29 | */5 * * * * /usr/sbin/ntpdate time.nist.gov 30 | ``` 31 | 32 | ##### 4. Write the system time to the BIOS 33 | 34 | ``` 35 | sudo hwclock -w 36 | ``` 37 | 38 | ##### 5. Verify 39 | 40 | Modify the local time, and automatically synchronize the correct time after five minutes. 41 | 42 | -------------------------------------------------------------------------------- /src/main/resources/xdag-mainnet.conf: -------------------------------------------------------------------------------- 1 | # Admin Config 2 | admin.telnet.ip = 127.0.0.1 3 | admin.telnet.port = 6001 4 | admin.telnet.password = 123 5 | 6 | # Pool websocket Config (Node <--> Pools) 7 | pool.whiteIPs = ["0.0.0.0"] 8 | pool.ws.port = 7001 9 | 10 | # Node config (Node <--> Node) 11 | node.ip = 127.0.0.1 12 | node.port = 8001 13 | node.tag = XdagJ 14 | node.maxInboundConnectionsPerIp = 8 15 | node.whiteIPs = ["127.0.0.1:8002"] 16 | node.generate.block.enable = true 17 | node.reject.transaction.address = 111111111111111111117K4nzc 18 | node.ration = 5 19 | 20 | # Fund config 21 | fund.address = "PKcBtHWDSnAWfZntqWPBLedqBShuKSTzS" 22 | fund.ration = 5 23 | 24 | # Node transaction history config 25 | node.transaction.history.enable = true 26 | node.transaction.history.pageSizeLimit = 500 27 | 28 | # Node RPC Config 29 | rpc.http.enabled = true 30 | rpc.http.host = 127.0.0.1 31 | rpc.http.port = 10001 32 | rpc.ws.port = 10002 33 | 34 | 35 | # Randomx Config 36 | randomx.flags.fullmem = false -------------------------------------------------------------------------------- /script/xdag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ulimit -n unlimited 4 | 5 | XDAG_VERSION="${project.version}" 6 | XDAG_JARNAME="xdagj-${XDAG_VERSION}-executable.jar" 7 | XDAG_OPTS="-t" 8 | 9 | # Linux Java Home 10 | #JAVA_HOME="/usr/local/java/" 11 | 12 | # MacOS Java Home 13 | #JAVA_HOME=/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/ 14 | 15 | # default JVM options 16 | JAVA_OPTS="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED -Xms4g -Xmx4g -XX:+ExitOnOutOfMemoryError -XX:+UseZGC" 17 | 18 | JAVA_HEAPDUMP="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./logs/xdag-heapdump" 19 | 20 | JAVA_GC_LOG="-Xlog:gc*,gc+heap=trace,gc+age=trace,safepoint:file=./logs/xdag-gc-%t.log:time,level,tid,tags:filecount=8,filesize=10m" 21 | 22 | XDAGJ_VERSION="-Dxdagj.version=${XDAG_VERSION}" 23 | 24 | if [ ! -d "logs" ];then 25 | mkdir "logs" 26 | fi 27 | 28 | # start kernel 29 | java ${JAVA_OPTS} ${JAVA_HEAPDUMP} ${JAVA_GC_LOG} ${XDAGJ_VERSION} -cp .:${XDAG_JARNAME} io.xdag.Bootstrap "$@" -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Feedback any useful bugs to help us improve the project 4 | title: 'BUG : ' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Title** 11 | Briefly describe your problem 12 | 13 | **Software information (please complete the following information)** 14 | - OS version : [eg. MacOS BigSur 11.1.2] 15 | - XDAGJ version : [eg. XDAGJ-0.4.1-Aplha] 16 | - JDK version : [eg. JDK21.0.2] 17 | 18 | **Describe the bug** 19 | A clear and concise description of what the bug is. 20 | 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Actual behavior** 26 | What actually happened 27 | 28 | **Log** 29 | Provide detailed logs so that we can troubleshoot problems. 30 | 31 | **Can Reproduce(option)** 32 | If can ,If you can, please tell us the detailed steps: 33 | 1. Go to '...' 34 | 2. Click on '....' 35 | 3. Scroll down to '....' 36 | 4. See error 37 | 38 | **Additional context** 39 | Add any other context about the problem here. 40 | -------------------------------------------------------------------------------- /docs/Win10_Configuration_RandomX_Algorithm_Environment_zh.md: -------------------------------------------------------------------------------- 1 | # Win10配置RandomX算法环境 2 | 3 | ## 开启本地安全组策略 4 | 5 | 该步骤仅家庭版用户需要操作,专业版默认打开本地安全组策略,用户无需操作 6 | 7 | - 新建空白txt文档,输入以下内容后保存 8 | 9 | ```shell 10 | @echo off 11 | 12 | pushd "%~dp0" 13 | 14 | dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt 15 | 16 | dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt 17 | 18 | for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"C:\Windows\servicing\Packages\%%i" 19 | 20 | pause 21 | ``` 22 | 23 | - 修改上述文件为xxx.bat文件,然后右键用管理员身份运行,等待程序运行结束即可 24 | 25 | ![Open the security group](img/Open_the_security_group.png) 26 | 27 | ## 开启hugeoage功能 28 | 29 | - 右键点击Win10电脑`开始` 30 | 31 | - 找到`windows管理工具`,并在里面到`本地安全策略`后打开 32 | 33 | ![RandomX_first](img/RandomX_first.png) 34 | 35 | - 点击`本地策略`->`用户权限分配`->`锁定内存页` 36 | 37 | ![RandomX_two](img/RandomX_two.png) 38 | 39 | - 为锁定内存页添加计算机用户名,确认之后重启电脑 40 | 41 | ![RandomX_three](img/RandomX_three.png) 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020-2030 The XdagJ Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /docs/XDAGJ_RPC_Service_Tutorial_en.md: -------------------------------------------------------------------------------- 1 | # XDAGJ RPC Service Tutorial 2 | 3 | This section describes XDAGJ RPC service. 4 | 5 | - [System environment](#system-environment) 6 | - [Usage](#usage) 7 | 8 | ## System environment 9 | 10 | ```yaml 11 | JDK : v21 12 | script : xdag.sh 13 | jar : xdagj-0.x.y-executable.jar 14 | ``` 15 | 16 | Please make sure that the above environment is already available in your operating system, and the JDK version must be 21 17 | 18 | 19 | ## Usage 20 | 21 | If you want to open the rpc service,you need to set "isRPCEnabled = true" in your configuration file. 22 | 23 | The configuration file is located in `src/main/resources/xdag-XXX.conf`, if you do not modify it, the default configuration is disabled. 24 | 25 | - Show XDAG synchronization status 26 | 27 | request 28 | ```js 29 | curl http://localhost:4444/ -s -X POST -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"xdag_syncing\",\"params\":[],\"id\":1}" 30 | ``` 31 | response 32 | ```json 33 | {"jsonrpc":"2.0","id":1,"result":{"currentBlock":"0x30331","highestBlock":"0x30331"}} 34 | ``` 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/cli/ShellTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.cli; 25 | 26 | public class ShellTest { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/cli/TelnetServerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.cli; 25 | 26 | public class TelnetServerTest { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/listener/Listener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.listener; 26 | 27 | public interface Listener { 28 | 29 | void onMessage(Message message); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/listener/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.listener; 26 | 27 | import io.xdag.config.Constants.MessageType; 28 | 29 | public interface Message { 30 | 31 | MessageType getType(); 32 | 33 | Object getData(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/rocksdb/DatabaseFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.rocksdb; 26 | 27 | public interface DatabaseFactory { 28 | 29 | KVSource getDB(DatabaseName name); 30 | 31 | /** 32 | * Close all opened resources. 33 | */ 34 | void close(); 35 | } 36 | -------------------------------------------------------------------------------- /docs/Win10_Configuration_RandomX_Algorithm_Environment_en.md: -------------------------------------------------------------------------------- 1 | # Win10 Configuration RandomX Algorithm Environment 2 | 3 | ### Enable local security group policy 4 | 5 | This step is only required for home version users, and the professional version opens the local security group policy by default, and users do not need to operate 6 | 7 | - Create a new blank txt file, enter the following content and save 8 | 9 | ```shell 10 | @echo off 11 | 12 | pushd "%~dp0" 13 | 14 | dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt 15 | 16 | dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt 17 | 18 | for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"C:\Windows\servicing\Packages\%%i" 19 | 20 | pause 21 | ``` 22 | 23 | - Modify the above file to xxx.bat file, then right-click to run as an administrator, and wait for the program to end 24 | 25 | ![Open the security group](img/Open_the_security_group.png) 26 | 27 | ### Open hugeoage 28 | 29 | - Right click on Win10 computer `Start` 30 | 31 | - Find the `windows management tool`, and open it after going to the `local security policy` 32 | 33 | ![RandomX_first](img/RandomX_first.png) 34 | 35 | - Click `Local Policies`->`User Rights Assignment`->`Lock Memory Pages` 36 | 37 | ![RandomX_two](img/RandomX_two.png) 38 | 39 | - Add the computer user name for the locked memory page, restart the computer after confirmation 40 | 41 | ![RandomX_three](img/RandomX_three.png) 42 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/pool/PoolAwardManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.pool; 25 | 26 | import org.apache.tuweni.bytes.Bytes32; 27 | 28 | public interface PoolAwardManager { 29 | 30 | void start(); 31 | 32 | void stop(); 33 | void addAwardBlock(Bytes32 share, Bytes32 preHash,Bytes32 hash, long generateTime); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/BlockExtRequestMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.net.message.MessageCode; 27 | 28 | public class BlockExtRequestMessage extends XdagMessage { 29 | public BlockExtRequestMessage(byte[] body) { 30 | super(MessageCode.BLOCKEXT_REQUEST, BlocksReplyMessage.class, body); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/response/NetConnResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.model.response; 25 | 26 | import lombok.Builder; 27 | import lombok.Data; 28 | import java.net.InetSocketAddress; 29 | 30 | @Data 31 | @Builder 32 | public class NetConnResponse { 33 | 34 | InetSocketAddress nodeAddress; 35 | long connectTime; 36 | long inBound; 37 | long outBound; 38 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/spec/RandomxSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.config.spec; 25 | 26 | /** 27 | * Interface for RandomX configuration specifications 28 | * Defines method to access RandomX flag setting 29 | */ 30 | public interface RandomxSpec { 31 | /** 32 | * Get the RandomX flag status 33 | * @return Boolean indicating if RandomX is enabled 34 | */ 35 | boolean getRandomxFlag(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/BlockExtReplyMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.net.message.Message; 27 | import io.xdag.net.message.MessageCode; 28 | 29 | public class BlockExtReplyMessage extends Message { 30 | 31 | public BlockExtReplyMessage(byte[] body) { 32 | super(MessageCode.BLOCKEXT_REPLY, null); 33 | 34 | this.body = body; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/consensus/XdagNatServiceConfigurationPowTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.consensus; 26 | 27 | import io.xdag.utils.XdagSha256Digest; 28 | import lombok.extern.slf4j.Slf4j; 29 | import org.junit.Before; 30 | 31 | @Slf4j 32 | public class XdagNatServiceConfigurationPowTest { 33 | 34 | XdagSha256Digest currentTaskDigest; 35 | 36 | @Before 37 | public void init() { 38 | currentTaskDigest = new XdagSha256Digest(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/execption/SerializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.execption; 26 | 27 | /** 28 | * {@link SerializationException} is thrown when there is a problem with serialization. 29 | */ 30 | public final class SerializationException extends SerDeException { 31 | 32 | public SerializationException( 33 | final String message, 34 | final Throwable throwable 35 | ) { 36 | super(message, throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/TransactionHistoryStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.db; 25 | 26 | import io.xdag.core.TxHistory; 27 | 28 | import java.util.List; 29 | 30 | public interface TransactionHistoryStore { 31 | 32 | boolean saveTxHistory(TxHistory txHistory); 33 | boolean batchSaveTxHistory(TxHistory txHistory,int... cacheNum); 34 | List listTxHistoryByAddress(String address, int page, Object... parameters); 35 | 36 | int getTxHistoryCount(String address); 37 | 38 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/execption/DeserializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.execption; 26 | 27 | /** 28 | * {@link DeserializationException} is thrown when there is a problem with deserialization. 29 | */ 30 | public final class DeserializationException extends SerDeException { 31 | 32 | public DeserializationException( 33 | final String message, 34 | final Throwable throwable 35 | ) { 36 | super(message, throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/rocksdb/DatabaseName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.rocksdb; 26 | 27 | public enum DatabaseName { 28 | 29 | /** 30 | * Block index. 31 | */ 32 | INDEX, 33 | 34 | /** 35 | * Block raw data. 36 | */ 37 | BLOCK, 38 | 39 | /** 40 | * Time related block. 41 | */ 42 | TIME, 43 | 44 | /** 45 | * Orphan block index 46 | */ 47 | ORPHANIND, 48 | 49 | SNAPSHOT, 50 | 51 | ADDRESS, 52 | 53 | TXHISTORY 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/consensus/PoW.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.consensus; 26 | 27 | /** 28 | * Interface for Proof of Work (PoW) implementation 29 | */ 30 | public interface PoW { 31 | 32 | /** 33 | * Processes new shares received from mining pool 34 | * 35 | * @param share The share data received from pool 36 | * @param hash The hash of the share 37 | * @param taskIndex The index of the mining task 38 | */ 39 | void receiveNewShare(String share, String hash, long taskIndex); 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/crypto/WalletTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.crypto; 25 | 26 | public class WalletTest { 27 | // public static void main(String[] args) throws Exception { 28 | // Native.init(); 29 | // if (Native.dnet_crypt_init() < 0) { 30 | // throw new Exception("dnet crypt init failed"); 31 | // } 32 | // byte[] array = new byte[8]; 33 | // byte[] random = Native.generate_random_bytes(array, 8); 34 | // System.out.println(Hex.toHexString(random)); 35 | // } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/execption/SerDeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.execption; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * Base class for serialization/deserialization exceptions. 31 | */ 32 | public abstract class SerDeException extends IOException { 33 | 34 | public SerDeException(final String message) { 35 | super(message); 36 | } 37 | 38 | public SerDeException( 39 | final String message, 40 | final Throwable throwable 41 | ) { 42 | super(message, throwable); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/LauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag; 25 | 26 | import org.apache.commons.cli.CommandLine; 27 | import org.apache.commons.cli.ParseException; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.assertTrue; 31 | 32 | public class LauncherTest { 33 | 34 | @Test 35 | public void testPasswordOption() throws ParseException { 36 | Launcher launcher = new Launcher(); 37 | CommandLine cmd = launcher.parseOptions(new String[]{"--password", "123"}); 38 | assertTrue(cmd.hasOption("password")); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/BlocksReplyMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.core.XdagStats; 27 | import io.xdag.net.message.MessageCode; 28 | 29 | public class BlocksReplyMessage extends XdagMessage { 30 | 31 | public BlocksReplyMessage(long starttime, long endtime, long random, XdagStats xdagStats) { 32 | super(MessageCode.BLOCKS_REPLY, null, starttime, endtime, random, xdagStats); 33 | } 34 | 35 | public BlocksReplyMessage(byte[] body) { 36 | super(MessageCode.BLOCKS_REPLY, null, body); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/Bootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag; 26 | 27 | import io.xdag.cli.XdagCli; 28 | 29 | /** 30 | * Bootstrap class that serves as the entry point for the XDAG application 31 | */ 32 | public class Bootstrap { 33 | 34 | /** 35 | * Main method that launches the XDAG CLI application 36 | * 37 | * @param args Command line arguments passed to the application 38 | * @throws Exception If any error occurs during application startup 39 | */ 40 | public static void main(String[] args) throws Exception { 41 | XdagCli.main(args); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/MessageException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message; 25 | 26 | import java.io.IOException; 27 | 28 | public class MessageException extends IOException { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | public MessageException() { 33 | } 34 | 35 | public MessageException(String s) { 36 | super(s); 37 | } 38 | 39 | public MessageException(String s, Throwable throwable) { 40 | super(s, throwable); 41 | } 42 | 43 | public MessageException(Throwable throwable) { 44 | super(throwable); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/spec/WalletSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config.spec; 26 | 27 | /** 28 | * Interface for wallet configuration specifications 29 | * Defines methods to access wallet file paths and settings 30 | */ 31 | public interface WalletSpec { 32 | 33 | /** 34 | * Get the wallet key file location 35 | * @return String containing the path to the wallet key file 36 | */ 37 | String getWalletKeyFile(); 38 | 39 | /** 40 | * Get the wallet file path 41 | * @return String containing the path to the wallet file 42 | */ 43 | String getWalletFilePath(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/response/ProcessResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.model.response; 25 | 26 | import java.util.List; 27 | import lombok.Builder; 28 | import lombok.Data; 29 | 30 | @Builder 31 | @Data 32 | public class ProcessResponse { 33 | 34 | private int code; // success:0 failed:err code 35 | private List result; // if success return tx hash, else return errMsg 36 | private String errMsg; 37 | 38 | public List getResInfo() { 39 | return result; 40 | } 41 | 42 | public void setResInfo(List result) { 43 | this.result = result; 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/listener/PretopMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.listener; 25 | 26 | import io.xdag.config.Constants.MessageType; 27 | import org.apache.tuweni.bytes.Bytes; 28 | 29 | public class PretopMessage implements Message { 30 | 31 | Bytes data; 32 | MessageType type; 33 | 34 | public PretopMessage(Bytes data, MessageType type) { 35 | this.data = data; 36 | this.type = type; 37 | } 38 | 39 | @Override 40 | public MessageType getType() { 41 | return type; 42 | } 43 | 44 | @Override 45 | public Bytes getData() { 46 | return data; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/listener/BlockMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.listener; 25 | 26 | import io.xdag.config.Constants.MessageType; 27 | import org.apache.tuweni.bytes.Bytes; 28 | 29 | 30 | public class BlockMessage implements Message { 31 | 32 | Bytes data; 33 | MessageType type; 34 | 35 | public BlockMessage(Bytes data, MessageType type) { 36 | this.data = data; 37 | this.type = type; 38 | } 39 | 40 | @Override 41 | public MessageType getType() { 42 | return type; 43 | } 44 | 45 | @Override 46 | public Bytes getData() { 47 | return data; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/spec/FundSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.config.spec; 25 | 26 | /** 27 | * Interface for fund configuration specifications 28 | * Defines methods to access fund parameters 29 | */ 30 | public interface FundSpec { 31 | /** 32 | * Get the fund ratio for distribution 33 | * @return Double containing the fund ratio value 34 | */ 35 | double getFundRation(); // Note: There is a typo in method name, should be "getFundRatio" 36 | 37 | /** 38 | * Get the fund receiving address 39 | * @return String containing the fund address 40 | */ 41 | String getFundAddress(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/BlocksRequestMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.core.XdagStats; 27 | import io.xdag.net.message.MessageCode; 28 | import io.xdag.utils.XdagRandomUtils; 29 | 30 | public class BlocksRequestMessage extends XdagMessage { 31 | public BlocksRequestMessage(long starttime, long endtime, XdagStats xdagStats) { 32 | super(MessageCode.BLOCKS_REQUEST, null, starttime, endtime, XdagRandomUtils.nextLong(Long.MAX_VALUE), xdagStats); 33 | } 34 | 35 | public BlocksRequestMessage(byte[] body) { 36 | super(MessageCode.BLOCKS_REQUEST, null, body); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/SumRequestMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.core.XdagStats; 27 | import io.xdag.net.message.MessageCode; 28 | import io.xdag.utils.XdagRandomUtils; 29 | 30 | public class SumRequestMessage extends XdagMessage { 31 | public SumRequestMessage(long starttime, long endtime, XdagStats xdagStats) { 32 | super(MessageCode.SUMS_REQUEST, SumReplyMessage.class, starttime, endtime, XdagRandomUtils.nextLong(Long.MAX_VALUE), xdagStats); 33 | } 34 | 35 | public SumRequestMessage(byte[] body) { 36 | super(MessageCode.SUMS_REQUEST, SumReplyMessage.class, body); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/response/XdagStatusResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.rpc.model.response; 26 | 27 | import lombok.Builder; 28 | import lombok.Data; 29 | 30 | @Data 31 | @Builder 32 | public class XdagStatusResponse { 33 | 34 | // status info 35 | private final String nblock; 36 | private final String totalNblocks; 37 | private final String nmain; 38 | private final String totalNmain; 39 | private final String curDiff; 40 | private final String netDiff; 41 | private final String hashRateOurs; 42 | private final String hashRateTotal; 43 | 44 | private final String ourSupply; 45 | private final String netSupply; 46 | 47 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/BlockRequestMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | 27 | 28 | import org.apache.tuweni.bytes.Bytes32; 29 | import org.apache.tuweni.bytes.MutableBytes; 30 | 31 | import io.xdag.core.XdagStats; 32 | import io.xdag.net.message.MessageCode; 33 | 34 | public class BlockRequestMessage extends XdagMessage { 35 | 36 | public BlockRequestMessage(MutableBytes hash, XdagStats xdagStats) { 37 | super(MessageCode.BLOCK_REQUEST, null, 0, 0, Bytes32.wrap(hash), xdagStats); 38 | } 39 | 40 | public BlockRequestMessage(byte[] body) { 41 | super(MessageCode.BLOCK_REQUEST, null, body); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/server/handler/JsonRpcRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.server.handler; 25 | 26 | import io.xdag.rpc.error.JsonRpcException; 27 | import io.xdag.rpc.server.protocol.JsonRpcRequest; 28 | 29 | public interface JsonRpcRequestHandler { 30 | /** 31 | * 处理RPC请求 32 | * 33 | * @param request RPC请求 34 | * @return 处理结果 35 | * @throws JsonRpcException 如果处理过程中出现错误 36 | */ 37 | Object handle(JsonRpcRequest request) throws JsonRpcException; 38 | 39 | /** 40 | * 检查方法是否支持 41 | * 42 | * @param methodName 方法名 43 | * @return 如果支持返回true 44 | */ 45 | boolean supportsMethod(String methodName); 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/message/MessageFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message; 25 | 26 | import static org.junit.Assert.assertNull; 27 | 28 | import org.junit.Test; 29 | 30 | public class MessageFactoryTest { 31 | 32 | @Test 33 | public void testNonExist() throws MessageException { 34 | MessageFactory factory = new MessageFactory(); 35 | assertNull(factory.create((byte) 0xff, new byte[1])); 36 | } 37 | 38 | @Test(expected = MessageException.class) 39 | public void testWrongCodec() throws MessageException { 40 | MessageFactory factory = new MessageFactory(); 41 | factory.create((byte) 0x01, new byte[1]); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/message/ReasonCodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertNull; 28 | 29 | import org.junit.Test; 30 | 31 | public class ReasonCodeTest { 32 | 33 | @Test 34 | public void testConverting() { 35 | for (ReasonCode code : ReasonCode.values()) { 36 | assertEquals(code, ReasonCode.of(code.getCode())); 37 | assertEquals(code, ReasonCode.of(code.toByte())); 38 | } 39 | } 40 | 41 | @Test 42 | public void testNegativeByte() { 43 | byte b = (byte) 0xff; 44 | assertNull(MessageCode.of(b)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/message/MessageCodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertNull; 28 | 29 | import org.junit.Test; 30 | 31 | public class MessageCodeTest { 32 | 33 | @Test 34 | public void testConverting() { 35 | for (MessageCode code : MessageCode.values()) { 36 | assertEquals(code, MessageCode.of(code.getCode())); 37 | assertEquals(code, MessageCode.of(code.toByte())); 38 | } 39 | } 40 | 41 | @Test 42 | public void testNegativeByte() { 43 | byte b = (byte) 0xff; 44 | assertNull(MessageCode.of(b)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/server/protocol/JsonRpcErrorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.server.protocol; 25 | 26 | import com.fasterxml.jackson.annotation.JsonProperty; 27 | import io.xdag.rpc.error.JsonRpcError; 28 | import lombok.Getter; 29 | import lombok.Setter; 30 | 31 | /** 32 | * 33 | */ 34 | @Getter 35 | public class JsonRpcErrorResponse { 36 | @JsonProperty("jsonrpc") 37 | private String jsonrpc = "2.0"; 38 | 39 | @JsonProperty("id") 40 | private int id; 41 | 42 | @JsonProperty("error") 43 | private JsonRpcError error; 44 | 45 | public JsonRpcErrorResponse(int id, JsonRpcError error) { 46 | this.id = id; 47 | this.error = error; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/OrphanBlockStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.db; 25 | 26 | import io.xdag.core.XdagLifecycle; 27 | import io.xdag.core.Address; 28 | import io.xdag.core.Block; 29 | import java.util.List; 30 | 31 | import org.bouncycastle.util.encoders.Hex; 32 | 33 | public interface OrphanBlockStore extends XdagLifecycle { 34 | 35 | byte ORPHAN_PREFEX = 0x00; 36 | /** 37 | * size key 38 | */ 39 | byte[] ORPHAN_SIZE = Hex.decode("FFFFFFFFFFFFFFFF"); 40 | 41 | void reset(); 42 | 43 | List
getOrphan(long num, long[] sendTime); 44 | 45 | void deleteByHash(byte[] hashlow); 46 | 47 | void addOrphan(Block block); 48 | 49 | long getOrphanSize(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/SyncBlockRequestMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import org.apache.tuweni.bytes.Bytes32; 27 | import org.apache.tuweni.bytes.MutableBytes; 28 | 29 | import io.xdag.core.XdagStats; 30 | import io.xdag.net.message.MessageCode; 31 | 32 | public class SyncBlockRequestMessage extends XdagMessage { 33 | 34 | public SyncBlockRequestMessage(MutableBytes hash, XdagStats xdagStats) { 35 | super(MessageCode.SYNCBLOCK_REQUEST, SyncBlockMessage.class, 0, 0, Bytes32.wrap(hash), xdagStats); 36 | } 37 | 38 | public SyncBlockRequestMessage(byte[] body) { 39 | super(MessageCode.SYNCBLOCK_REQUEST, null, body); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/response/ConfigResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.model.response; 25 | 26 | import lombok.AllArgsConstructor; 27 | import lombok.Builder; 28 | import lombok.Data; 29 | import lombok.NoArgsConstructor; 30 | 31 | /** 32 | * 33 | */ 34 | @Data 35 | @Builder 36 | @NoArgsConstructor 37 | @AllArgsConstructor 38 | public class ConfigResponse { 39 | String poolIp; 40 | int poolPort; 41 | String nodeIp; 42 | int nodePort; 43 | int globalMinerLimit; 44 | int maxConnectMinerPerIp; 45 | int maxMinerPerAccount; 46 | 47 | String poolFeeRation; 48 | String poolRewardRation; 49 | String poolDirectRation; 50 | String poolFundRation; 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/XdagLifecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | /** 27 | * Interface defining lifecycle methods for XDAG components. 28 | * Provides basic start/stop functionality and status checking. 29 | */ 30 | public interface XdagLifecycle { 31 | /** 32 | * Starts the component. 33 | * Should initialize resources and begin processing. 34 | */ 35 | void start(); 36 | 37 | /** 38 | * Stops the component. 39 | * Should cleanup resources and halt processing. 40 | */ 41 | void stop(); 42 | 43 | /** 44 | * Checks if the component is currently running. 45 | * 46 | * @return true if component is running, false otherwise 47 | */ 48 | boolean isRunning(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/spec/AdminSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config.spec; 26 | 27 | /** 28 | * Interface for admin configuration specifications 29 | * Defines methods to access telnet server configuration parameters 30 | */ 31 | public interface AdminSpec { 32 | 33 | /** 34 | * Get the IP address for the telnet server 35 | * @return String containing the telnet server IP address 36 | */ 37 | String getAdminTelnetIp(); 38 | 39 | /** 40 | * Get the port number for the telnet server 41 | * @return Integer containing the telnet server port number 42 | */ 43 | int getAdminTelnetPort(); 44 | 45 | /** 46 | * Get the password for telnet server authentication 47 | * @return String containing the telnet server password 48 | */ 49 | String getAdminTelnetPassword(); 50 | } 51 | -------------------------------------------------------------------------------- /docs/XDAGJ_Network_Protocol_en.md: -------------------------------------------------------------------------------- 1 | # Network Protocol 2 | 3 | Clients send messages to peers in order to interact with the blockchain. These can be 4 | divided into general peer messages, and consensus methods used by validators for forging blocks. 5 | 6 | Messages are written using the XDAGJ [XDAGJ_Message_Encoding](./XDAGJ_Message_Encoding_en.md) format. 7 | 8 | Messages send the code byte first, then the parameters in order 9 | 10 | 11 | ## Standard Message Objects 12 | 13 | ### Peer 14 | 15 | Message: 16 | - ip (string) 17 | - port (int) 18 | - networkVersion (short) 19 | - clientId (string) 20 | - peerId (string) 21 | - latestBlockNumber (long) 22 | - capabilities size (int) 23 | - capabilities[] (string[]) 24 | 25 | ## P2P Messages 26 | 27 | - [0x00, 0x0f] Reserved for p2p basics 28 | 29 | ### Disconnect 30 | 31 | Code: 0x00 32 | 33 | Inform a peer of disconnection. Reasons can include too many peers, invalid handshake, or other. 34 | 35 | Message: 36 | - reason (byte) 37 | 38 | ### Hello 39 | 40 | Code: 0x01 41 | 42 | Initiate a connection with a peer. No messages will be accepted until after this handshake is done. 43 | 44 | Message: 45 | - peer (Peer) 46 | - timestamp (long) 47 | - signature (byte[]) 48 | 49 | ### World 50 | 51 | Code: 0x02 52 | 53 | Respond to a Hello message indicating successful connection. 54 | 55 | Message: 56 | - peer (Peer) 57 | - timestamp (long) 58 | - signature (byte[]) 59 | 60 | ### Ping 61 | 62 | Code: 0x03 63 | 64 | Request a reply from the peer to ensure connection is still valid. 65 | 66 | Message: 67 | - timestamp (long) 68 | 69 | ### Pong 70 | 71 | Code: 0x04 72 | 73 | Respond to a Ping message. 74 | 75 | Message: 76 | - timestamp (long) 77 | 78 | ## Consensus Messages 79 | 80 | - [0x10, 0x1f] Reserved for node 81 | 82 | ### BLOCKS_REQUEST(0x10) 83 | ### BLOCKS_REPLY(0x11) 84 | ### SUMS_REQUEST(0x12) 85 | ### SUMS_REPLY(0x13) 86 | ### BLOCKEXT_REQUEST(0x14) 87 | ### BLOCKEXT_REPLY(0x15) 88 | ### BLOCK_REQUEST(0x16) 89 | ### RECEIVE_BLOCK(0x17) 90 | ### NEW_BLOCK(0x18) 91 | ### SYNC_BLOCK(0x19) 92 | ### SYNCBLOCK_REQUEST(0x1A) -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/XdagTopStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import java.math.BigInteger; 27 | import lombok.Getter; 28 | import lombok.Setter; 29 | 30 | /** 31 | * Top status of the block tree. 32 | * 33 | * @author ycx 34 | */ 35 | @Getter 36 | @Setter 37 | public class XdagTopStatus { 38 | 39 | /** 40 | * The top block hash. 41 | */ 42 | private byte[] top; 43 | 44 | /** 45 | * The top block difficulty. 46 | */ 47 | private BigInteger topDiff; 48 | 49 | /** 50 | * The pre-top block hash. 51 | */ 52 | private byte[] preTop; 53 | 54 | /** 55 | * The pre-top block difficulty. 56 | */ 57 | private BigInteger preTopDiff; 58 | 59 | public XdagTopStatus() { 60 | topDiff = BigInteger.ZERO; 61 | preTopDiff = BigInteger.ZERO; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/CapabilityTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertFalse; 28 | import static org.junit.Assert.assertTrue; 29 | 30 | import org.junit.Test; 31 | 32 | public class CapabilityTest { 33 | 34 | @Test 35 | public void testIsSupported() { 36 | assertFalse(CapabilityTreeSet.emptyList().isSupported(Capability.FULL_NODE)); 37 | assertFalse(CapabilityTreeSet.of("FULL_NODE").isSupported(Capability.LIGHT_NODE)); 38 | assertTrue(CapabilityTreeSet.of("FULL_NODE").isSupported(Capability.FULL_NODE)); 39 | assertTrue(CapabilityTreeSet.of(Capability.FULL_NODE).isSupported(Capability.FULL_NODE)); 40 | assertEquals(CapabilityTreeSet.of(Capability.FULL_NODE), CapabilityTreeSet.of(Capability.FULL_NODE)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/rocksdb/KVSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.rocksdb; 26 | 27 | import java.util.List; 28 | import java.util.Set; 29 | import java.util.function.Function; 30 | import org.apache.commons.lang3.tuple.Pair; 31 | 32 | public interface KVSource { 33 | 34 | String getName(); 35 | 36 | void setName(String name); 37 | 38 | boolean isAlive(); 39 | 40 | void init(); 41 | 42 | void close(); 43 | 44 | void reset(); 45 | 46 | void put(K key, V val); 47 | 48 | V get(K key); 49 | 50 | void delete(K key); 51 | 52 | Set keys() throws RuntimeException; 53 | 54 | List prefixKeyLookup(byte[] key); 55 | 56 | void fetchPrefix(byte[] key, Function, Boolean> func); 57 | 58 | List prefixValueLookup(byte[] key); 59 | 60 | List> prefixKeyAndValueLookup(byte[] key); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/Capability.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net; 25 | 26 | /** 27 | * Enum representing different node capabilities in the XDAG network 28 | */ 29 | public enum Capability { 30 | /** 31 | * Represents a full node that maintains the complete blockchain 32 | */ 33 | FULL_NODE, 34 | 35 | /** 36 | * Represents a light node that only stores block headers 37 | */ 38 | LIGHT_NODE; 39 | 40 | /** 41 | * Creates a Capability enum from a string name 42 | * 43 | * @param name The name of the capability 44 | * @return The corresponding Capability enum value, or null if invalid 45 | */ 46 | public static Capability of(String name) { 47 | try { 48 | return valueOf(name); 49 | } catch (IllegalArgumentException | NullPointerException ex) { 50 | return null; 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/message/p2p/InitMessageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.p2p; 25 | 26 | import static org.junit.Assert.assertArrayEquals; 27 | import static org.junit.Assert.assertEquals; 28 | 29 | import org.hyperledger.besu.crypto.SecureRandomProvider; 30 | import org.junit.Test; 31 | 32 | public class InitMessageTest { 33 | 34 | @Test 35 | public void testCodec() { 36 | byte[] secret = SecureRandomProvider.publicSecureRandom().generateSeed(32); 37 | long timestamp = System.currentTimeMillis(); 38 | 39 | InitMessage msg = new InitMessage(secret, timestamp); 40 | assertArrayEquals(secret, msg.getSecret()); 41 | assertEquals(timestamp, msg.getTimestamp()); 42 | 43 | msg = new InitMessage(msg.getBody()); 44 | assertArrayEquals(secret, msg.getSecret()); 45 | assertEquals(timestamp, msg.getTimestamp()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/config/ConstantsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | import io.xdag.core.XUnit; 30 | 31 | import org.apache.tuweni.units.bigints.UInt64; 32 | import org.junit.Test; 33 | 34 | public class ConstantsTest { 35 | 36 | @Test 37 | public void testMainStartAmount() { 38 | Config config = new MainnetConfig(); 39 | UInt64 startAmount = UInt64.valueOf(1L << 42); 40 | UInt64 apolloStartAmount = UInt64.valueOf(1L << 39); 41 | assertEquals(config.getMainStartAmount().toXAmount().toLong(), startAmount.toLong()); 42 | assertEquals(config.getApolloForkAmount().toXAmount().toLong(), apolloStartAmount.toLong()); 43 | assertEquals("1024.0", config.getMainStartAmount().toDecimal(1, XUnit.XDAG).toString()); 44 | assertEquals("128.0", config.getApolloForkAmount().toDecimal(1, XUnit.XDAG).toString()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.net.message; 26 | 27 | import org.apache.tuweni.bytes.Bytes; 28 | 29 | import lombok.Getter; 30 | 31 | @Getter 32 | public abstract class Message { 33 | 34 | /** 35 | * Message code. 36 | */ 37 | protected final MessageCode code; 38 | 39 | /** 40 | * Response message class. 41 | */ 42 | protected final Class responseMessageClass; 43 | 44 | /** 45 | * Message body. 46 | */ 47 | protected byte[] body; 48 | 49 | /** 50 | * Create a message instance. 51 | */ 52 | public Message(MessageCode code, Class responseMessageClass) { 53 | this.code = code; 54 | this.responseMessageClass = responseMessageClass; 55 | this.body = Bytes.EMPTY.toArray(); 56 | } 57 | 58 | /** 59 | * Return the message name. 60 | */ 61 | public String toString() { 62 | return getClass().getName(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/utils/XdagNatServiceConfigurationTimeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.utils; 26 | 27 | import static org.junit.Assert.assertTrue; 28 | 29 | import java.text.ParseException; 30 | import java.util.Date; 31 | import org.apache.commons.lang3.time.DateUtils; 32 | import org.apache.commons.lang3.time.FastDateFormat; 33 | import org.junit.Test; 34 | 35 | public class XdagNatServiceConfigurationTimeTest { 36 | 37 | @Test 38 | public void testGetEndOfEpoch() throws ParseException { 39 | Date date1 = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").parse("2020-09-20 23:00:00"); 40 | Date date2 = new Date(XdagTime.getEndOfEpoch(date1.getTime())); 41 | for (int i = 0; i < 10; i++) { 42 | long epoch2 = XdagTime.getEpoch(date2.getTime()); 43 | Date date3 = DateUtils.addSeconds(date2, 64); 44 | long epoch3 = XdagTime.getEpoch(date3.getTime()); 45 | assertTrue(epoch3 > epoch2); 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/BlockState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import lombok.Getter; 27 | 28 | /** 29 | * Enum representing the different states a block can be in 30 | * MAIN - Block is part of the main chain 31 | * REJECTED - Block has been rejected 32 | * ACCEPTED - Block has been accepted but not yet in main chain 33 | * PENDING - Block is pending validation 34 | */ 35 | @Getter 36 | public enum BlockState { 37 | MAIN(0, "Main"), 38 | REJECTED(1, "Rejected"), 39 | ACCEPTED(2, "Accepted"), 40 | PENDING(3, "Pending"); 41 | 42 | // Numeric code representing the state 43 | private final int code; 44 | // Human readable description of the state 45 | private final String desc; 46 | 47 | /** 48 | * Constructor for BlockState enum 49 | * @param code Numeric code for the state 50 | * @param desc Description of the state 51 | */ 52 | BlockState(int code, String desc) { 53 | this.code = code; 54 | this.desc = desc; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/p2p/PongMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.p2p; 25 | 26 | import io.xdag.utils.SimpleEncoder; 27 | import io.xdag.net.message.Message; 28 | import io.xdag.net.message.MessageCode; 29 | import io.xdag.utils.SimpleDecoder; 30 | 31 | public class PongMessage extends Message { 32 | 33 | private final long timestamp; 34 | 35 | public PongMessage() { 36 | super(MessageCode.PONG, null); 37 | 38 | this.timestamp = System.currentTimeMillis(); 39 | 40 | SimpleEncoder enc = new SimpleEncoder(); 41 | enc.writeLong(timestamp); 42 | this.body = enc.toBytes(); 43 | } 44 | 45 | public PongMessage(byte[] body) { 46 | super(MessageCode.PONG, null); 47 | 48 | SimpleDecoder dec = new SimpleDecoder(body); 49 | this.timestamp = dec.readLong(); 50 | 51 | this.body = body; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "PongMessage [timestamp=" + timestamp + "]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/p2p/PingMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.p2p; 25 | 26 | import io.xdag.utils.SimpleEncoder; 27 | import io.xdag.net.message.Message; 28 | import io.xdag.net.message.MessageCode; 29 | import io.xdag.utils.SimpleDecoder; 30 | 31 | public class PingMessage extends Message { 32 | 33 | private final long timestamp; 34 | 35 | public PingMessage() { 36 | super(MessageCode.PING, PongMessage.class); 37 | 38 | this.timestamp = System.currentTimeMillis(); 39 | 40 | SimpleEncoder enc = new SimpleEncoder(); 41 | enc.writeLong(timestamp); 42 | this.body = enc.toBytes(); 43 | } 44 | 45 | public PingMessage(byte[] body) { 46 | super(MessageCode.PING, PongMessage.class); 47 | 48 | SimpleDecoder dec = new SimpleDecoder(body); 49 | this.timestamp = dec.readLong(); 50 | 51 | this.body = body; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "PingMessage [timestamp=" + timestamp + "]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/utils/BytesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.utils; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | import java.nio.charset.StandardCharsets; 29 | 30 | import org.apache.tuweni.bytes.Bytes; 31 | import org.apache.tuweni.bytes.Bytes32; 32 | import org.apache.tuweni.bytes.MutableBytes32; 33 | import org.junit.Test; 34 | 35 | import io.xdag.crypto.Hash; 36 | 37 | public class BytesTest { 38 | 39 | @Test 40 | public void testSetMutableBytes32() { 41 | MutableBytes32 hashlow = MutableBytes32.create(); 42 | Bytes32 hash = Hash.hashTwice(Bytes.wrap("123".getBytes(StandardCharsets.UTF_8))); 43 | assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000", hashlow.toHexString()); 44 | assertEquals("0x5a77d1e9612d350b3734f6282259b7ff0a3f87d62cfef5f35e91a5604c0490a3", hash.toHexString()); 45 | hashlow.set(8, hash.slice(8, 24)); 46 | assertEquals("0x00000000000000003734f6282259b7ff0a3f87d62cfef5f35e91a5604c0490a3", hashlow.toHexString()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/SumReplyMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import org.apache.tuweni.bytes.MutableBytes; 27 | 28 | import io.xdag.utils.SimpleEncoder; 29 | import io.xdag.core.XdagStats; 30 | import io.xdag.net.message.MessageCode; 31 | import io.xdag.utils.SimpleDecoder; 32 | import lombok.Getter; 33 | import lombok.Setter; 34 | 35 | @Getter 36 | @Setter 37 | public class SumReplyMessage extends XdagMessage { 38 | 39 | MutableBytes sum; 40 | 41 | public SumReplyMessage(long endtime, long random, XdagStats xdagStats, MutableBytes sum) { 42 | super(MessageCode.SUMS_REPLY, null, 1, endtime, random, xdagStats); 43 | 44 | SimpleEncoder enc = super.encode(); 45 | enc.writeBytes(sum.toArray()); 46 | this.body = enc.toBytes(); 47 | } 48 | 49 | public SumReplyMessage(byte[] body) { 50 | super(MessageCode.SUMS_REPLY, null, body); 51 | 52 | SimpleDecoder dec = super.decode(); 53 | this.sum = MutableBytes.wrap(dec.readBytes()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/config/MainnetConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD; 28 | import static org.junit.Assert.assertEquals; 29 | 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | import io.xdag.core.XUnit; 34 | 35 | public class MainnetConfigTest { 36 | 37 | private Config config; 38 | 39 | @Before 40 | public void setUp() { 41 | config = new MainnetConfig(); 42 | } 43 | 44 | @Test 45 | public void testParams() { 46 | assertEquals("mainnet", config.getRootDir()); 47 | assertEquals("xdag-mainnet", config.getConfigName()); 48 | assertEquals(0x16940000000L, config.getXdagEra()); 49 | assertEquals(XDAG_FIELD_HEAD, config.getXdagFieldHeader()); 50 | assertEquals(1017323, config.getApolloForkHeight()); 51 | assertEquals("1024.0", String.valueOf(config.getMainStartAmount().toDecimal(1, XUnit.XDAG))); 52 | assertEquals("128.0", String.valueOf(config.getApolloForkAmount().toDecimal(1, XUnit.XDAG))); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/BlockType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import lombok.Getter; 27 | 28 | /** 29 | * Enum representing different types of blocks in the XDAG blockchain 30 | * MAIN_BLOCK - Main chain block that forms the blockchain 31 | * WALLET - Wallet block that stores account information 32 | * TRANSACTION - Transaction block that records transfers 33 | * SNAPSHOT - Snapshot block used for chain state backup 34 | */ 35 | @Getter 36 | public enum BlockType { 37 | MAIN_BLOCK(0, "Main"), 38 | WALLET(1, "Wallet"), 39 | TRANSACTION(2, "Transaction"), 40 | SNAPSHOT(3, "Snapshot"); 41 | 42 | // Numeric code representing the block type 43 | private final int code; 44 | // Human readable description of the block type 45 | private final String desc; 46 | 47 | /** 48 | * Constructor for BlockType enum 49 | * @param code Numeric code for the block type 50 | * @param desc Description of the block type 51 | */ 52 | BlockType(int code, String desc) { 53 | this.code = code; 54 | this.desc = desc; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/config/TestnetConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST; 28 | import static org.junit.Assert.assertEquals; 29 | 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | import io.xdag.core.XUnit; 34 | 35 | public class TestnetConfigTest { 36 | 37 | private Config config; 38 | 39 | @Before 40 | public void setUp() { 41 | config = new TestnetConfig(); 42 | } 43 | 44 | @Test 45 | public void testParams() { 46 | assertEquals("testnet", config.getRootDir()); 47 | assertEquals("xdag-testnet", config.getConfigName()); 48 | assertEquals(0x16900000000L, config.getXdagEra()); 49 | assertEquals(XDAG_FIELD_HEAD_TEST, config.getXdagFieldHeader()); 50 | assertEquals(196250, config.getApolloForkHeight()); 51 | assertEquals("1024.0", String.valueOf(config.getMainStartAmount().toDecimal(1, XUnit.XDAG))); 52 | assertEquals("128.0", String.valueOf(config.getApolloForkAmount().toDecimal(1, XUnit.XDAG))); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/spec/RPCSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config.spec; 26 | 27 | /** 28 | * Interface for RPC configuration specifications 29 | * Defines methods to access RPC server configuration parameters 30 | */ 31 | public interface RPCSpec { 32 | 33 | /** 34 | * Check if RPC http server is enabled 35 | * @return Boolean indicating if RPC is enabled 36 | */ 37 | boolean isRpcHttpEnabled(); 38 | 39 | /** 40 | * Get the host address for RPC http server 41 | * @return String containing the RPC server host address 42 | */ 43 | String getRpcHttpHost(); 44 | 45 | /** 46 | * Get the port number for RPC HTTP server 47 | * @return Integer containing the RPC server HTTP port number 48 | */ 49 | int getRpcHttpPort(); 50 | 51 | boolean isRpcEnableHttps(); 52 | 53 | String getRpcHttpCorsOrigins(); 54 | 55 | int getRpcHttpMaxContentLength(); 56 | 57 | int getRpcHttpBossThreads(); 58 | 59 | int getRpcHttpWorkerThreads(); 60 | 61 | String getRpcHttpsCertFile(); 62 | 63 | String getRpcHttpsKeyFile(); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/XdagExtStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import static io.xdag.config.Constants.HASH_RATE_LAST_MAX_TIME; 27 | 28 | import java.math.BigInteger; 29 | import java.util.Arrays; 30 | import lombok.Getter; 31 | import lombok.Setter; 32 | 33 | /** 34 | * Class for tracking extended XDAG statistics including hash rates 35 | */ 36 | @Getter 37 | @Setter 38 | public class XdagExtStats { 39 | // Array to store total network hash rate history 40 | private BigInteger[] hashRateTotal = new BigInteger[HASH_RATE_LAST_MAX_TIME]; 41 | // Array to store our node's hash rate history 42 | private BigInteger[] hashRateOurs = new BigInteger[HASH_RATE_LAST_MAX_TIME]; 43 | // Timestamp of last hash rate update 44 | private long hashrate_last_time; 45 | 46 | /** 47 | * Constructor that initializes hash rate arrays to zero 48 | * and sets initial timestamp 49 | */ 50 | public XdagExtStats() { 51 | Arrays.fill(hashRateTotal, BigInteger.ZERO); 52 | Arrays.fill(hashRateOurs, BigInteger.ZERO); 53 | hashrate_last_time = 0L; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/crypto/RandomXMemory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.crypto; 26 | 27 | import io.xdag.crypto.randomx.RandomXTemplate; 28 | import lombok.Getter; 29 | import lombok.Setter; 30 | 31 | /** 32 | * Represents the memory state for RandomX, holding 33 | * relevant parameters for the computation. 34 | */ 35 | @Getter 36 | @Setter 37 | public class RandomXMemory { 38 | 39 | protected byte[] seed; // The seed used for RandomX 40 | protected long seedHeight; // The height at which the seed was created 41 | protected long seedTime; // The time when the seed was created 42 | protected long switchTime; // The time when the algorithm switched 43 | protected int isSwitched; // Flag to indicate if the algorithm has switched 44 | 45 | protected RandomXTemplate poolTemplate; // Template for the pool 46 | protected RandomXTemplate blockTemplate; // Template for the block 47 | 48 | public RandomXMemory() { 49 | this.switchTime = -1; // Initialize switchTime to -1 indicating no switch 50 | this.isSwitched = -1; // Initialize isSwitched to -1 indicating not switched 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/node/Node.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.net.node; 26 | 27 | import java.net.InetSocketAddress; 28 | import lombok.Getter; 29 | 30 | @Getter 31 | public class Node { 32 | 33 | private final InetSocketAddress address; 34 | 35 | public Node(InetSocketAddress address) { 36 | this.address = address; 37 | } 38 | 39 | public Node(String ip, int port) { 40 | this(new InetSocketAddress(ip, port)); 41 | } 42 | 43 | public String getIp() { 44 | return address.getAddress().getHostAddress(); 45 | } 46 | 47 | public int getPort() { 48 | return address.getPort(); 49 | } 50 | 51 | public InetSocketAddress toAddress() { 52 | return this.address; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return address.hashCode(); 58 | } 59 | 60 | @Override 61 | public boolean equals(Object o) { 62 | return o instanceof Node && address.equals(((Node) o).toAddress()); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return getIp() + ":" + getPort(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/SnapshotStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.db; 25 | 26 | import io.xdag.core.BlockInfo; 27 | import io.xdag.core.PreBlockInfo; 28 | import io.xdag.core.XAmount; 29 | import io.xdag.db.rocksdb.RocksdbKVSource; 30 | import java.util.List; 31 | import org.hyperledger.besu.crypto.KeyPair; 32 | import org.rocksdb.RocksIterator; 33 | 34 | public interface SnapshotStore { 35 | 36 | void init(); 37 | 38 | void reset(); 39 | 40 | void makeSnapshot(RocksdbKVSource blockSource,RocksdbKVSource indexSource,boolean b); 41 | 42 | void saveSnapshotToIndex(BlockStore blockStore, TransactionHistoryStore txHistoryStore, List keys,long snapshotTime); 43 | 44 | void saveAddress(BlockStore blockStore,AddressStore addressStore, TransactionHistoryStore txHistoryStore, List keys,long snapshotTime); 45 | 46 | void save(RocksIterator iter, BlockInfo blockInfo); 47 | 48 | void setBlockInfo(BlockInfo blockInfo, PreBlockInfo preBlockInfo); 49 | 50 | XAmount getOurBalance(); 51 | 52 | long getNextTime(); 53 | 54 | long getHeight(); 55 | 56 | XAmount getAllBalance(); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/p2p/DisconnectMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.p2p; 25 | 26 | import io.xdag.utils.SimpleEncoder; 27 | import io.xdag.net.message.Message; 28 | import io.xdag.net.message.MessageCode; 29 | import io.xdag.net.message.ReasonCode; 30 | import io.xdag.utils.SimpleDecoder; 31 | import lombok.Getter; 32 | 33 | @Getter 34 | public class DisconnectMessage extends Message { 35 | 36 | private final ReasonCode reason; 37 | 38 | public DisconnectMessage(ReasonCode reason) { 39 | super(MessageCode.DISCONNECT, null); 40 | 41 | this.reason = reason; 42 | 43 | SimpleEncoder enc = new SimpleEncoder(); 44 | enc.writeByte(reason.toByte()); 45 | this.body = enc.toBytes(); 46 | } 47 | 48 | public DisconnectMessage(byte[] body) { 49 | super(MessageCode.DISCONNECT, null); 50 | 51 | SimpleDecoder dec = new SimpleDecoder(body); 52 | this.reason = ReasonCode.of(dec.readByte()); 53 | 54 | this.body = body; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "DisconnectMessage [reason=" + reason + "]"; 60 | } 61 | } -------------------------------------------------------------------------------- /src/test/java/io/xdag/config/DevnetConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST; 28 | import static org.junit.Assert.assertEquals; 29 | 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | import io.xdag.core.XUnit; 34 | 35 | public class DevnetConfigTest { 36 | 37 | private Config config; 38 | 39 | @Before 40 | public void setUp() { 41 | config = new DevnetConfig(); 42 | } 43 | 44 | @Test 45 | public void testParams() { 46 | assertEquals("devnet", config.getRootDir()); 47 | assertEquals("xdag-devnet", config.getConfigName()); 48 | assertEquals(0x16900000000L, config.getXdagEra()); 49 | assertEquals(XDAG_FIELD_HEAD_TEST, config.getXdagFieldHeader()); 50 | assertEquals(1000, config.getApolloForkHeight()); 51 | assertEquals("1024.0", String.valueOf(config.getMainStartAmount().toDecimal(1, XUnit.XDAG))); 52 | assertEquals("128.0", String.valueOf(config.getApolloForkAmount().toDecimal(1, XUnit.XDAG))); 53 | assertEquals(8, config.getNodeSpec().getMaxInboundConnectionsPerIp()); 54 | assertEquals(888L, config.getTxPageSizeLimit()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/XUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import static java.util.Arrays.stream; 27 | import java.math.BigInteger; 28 | 29 | /** 30 | * XUnit 31 | * Represents different units of XDAG cryptocurrency 32 | * NANO_XDAG: 1 NANO_XDAG = 1 = 10^-9 XDAG 33 | * MICRO_XDAG: 10^3 NANO_XDAG = 1,000 = 10^-6 XDAG 34 | * MILLI_XDAG: 10^6 NANO_XDAG = 1,000,000 = 10^-3 XDAG 35 | * XDAG: 10^9 NANO_XDAG = 1,000,000,000 = 1 XDAG 36 | */ 37 | public enum XUnit { 38 | 39 | NANO_XDAG(0, "nXDAG"), 40 | MICRO_XDAG(3, "μXDAG"), 41 | MILLI_XDAG(6, "mXDAG"), 42 | XDAG(9, "XDAG"); 43 | 44 | public final int exp; 45 | public final long factor; 46 | public final String symbol; 47 | 48 | XUnit(int exp, String symbol) { 49 | this.exp = exp; 50 | this.factor = BigInteger.TEN.pow(exp).longValueExact(); 51 | this.symbol = symbol; 52 | } 53 | 54 | /** 55 | * Decode the unit from symbol. 56 | * 57 | * @param symbol the symbol text 58 | * @return a XUnit object if valid; otherwise null 59 | */ 60 | public static XUnit of(String symbol) { 61 | return stream(values()).filter(v -> v.symbol.equals(symbol)).findAny().orElse(null); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/PreBlockInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import java.math.BigInteger; 27 | import lombok.Getter; 28 | import lombok.Setter; 29 | 30 | /** 31 | * Class representing preliminary block information before full block creation 32 | */ 33 | @Getter 34 | @Setter 35 | public class PreBlockInfo { 36 | 37 | // Block type (main/wallet/transaction/snapshot) 38 | public long type; 39 | // Block flags for various attributes 40 | public int flags; 41 | // Block height in the chain 42 | private long height; 43 | // Block mining difficulty 44 | private BigInteger difficulty; 45 | // Reference to previous blocks 46 | private byte[] ref; 47 | // Link to block with maximum difficulty 48 | private byte[] maxDiffLink; 49 | // Transaction fee amount 50 | private long fee; 51 | // Block remark/memo field 52 | private byte[] remark; 53 | // Block full hash 54 | private byte[] hash; 55 | // Block truncated hash 56 | private byte[] hashlow; 57 | // Block amount/value 58 | private XAmount amount; 59 | // Block timestamp 60 | private long timestamp; 61 | 62 | // Snapshot related fields 63 | private boolean isSnapshot = false; 64 | private SnapshotInfo snapshotInfo = null; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/RandomXConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | /** 28 | * Constants related to RandomX mining algorithm implementation 29 | */ 30 | public class RandomXConstants { 31 | 32 | /** 33 | * Number of blocks in one epoch for mainnet 34 | */ 35 | public static final long SEEDHASH_EPOCH_BLOCKS = 4096; 36 | 37 | /** 38 | * Lag in blocks for seed hash calculation in mainnet 39 | */ 40 | public static final long SEEDHASH_EPOCH_LAG = 128; 41 | 42 | /** 43 | * Block height at which RandomX fork activates on mainnet 44 | */ 45 | public static final long RANDOMX_FORK_HEIGHT = 1540096; 46 | 47 | /** 48 | * Identifier for RandomX algorithm 49 | */ 50 | public static final int XDAG_RANDOMX = 2; 51 | 52 | /** 53 | * Number of blocks in one epoch for testnet 54 | */ 55 | public static long SEEDHASH_EPOCH_TESTNET_BLOCKS = 2048; 56 | 57 | /** 58 | * Lag in blocks for seed hash calculation in testnet 59 | */ 60 | public static long SEEDHASH_EPOCH_TESTNET_LAG = 64; 61 | 62 | /** 63 | * Block height at which RandomX fork activates on testnet 64 | * Note: Previous value was 196288 65 | */ 66 | public static long RANDOMX_TESTNET_FORK_HEIGHT = 4096; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/AbstractXdagLifecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.core; 26 | 27 | import java.util.concurrent.atomic.AtomicBoolean; 28 | 29 | /** 30 | * Abstract base class that implements common lifecycle management logic. 31 | * Subclasses only need to implement doStart() and doStop() methods. 32 | */ 33 | public abstract class AbstractXdagLifecycle implements XdagLifecycle { 34 | 35 | private final AtomicBoolean running = new AtomicBoolean(false); 36 | 37 | @Override 38 | public final void start() { 39 | if (running.compareAndSet(false, true)) { 40 | doStart(); 41 | } 42 | } 43 | 44 | @Override 45 | public final void stop() { 46 | if (running.compareAndSet(true, false)) { 47 | doStop(); 48 | } 49 | } 50 | 51 | @Override 52 | public final boolean isRunning() { 53 | return running.get(); 54 | } 55 | 56 | /** 57 | * Template method for subclasses to implement start logic. 58 | * This method is called only when the service is not running. 59 | */ 60 | protected abstract void doStart(); 61 | 62 | /** 63 | * Template method for subclasses to implement stop logic. 64 | * This method is called only when the service is running. 65 | */ 66 | protected abstract void doStop(); 67 | } -------------------------------------------------------------------------------- /misc/code-style/formatter_intellij.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 22 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/SnapshotInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.core; 25 | 26 | import java.util.Arrays; 27 | 28 | import lombok.Getter; 29 | import lombok.Setter; 30 | 31 | /** 32 | * Class representing snapshot information 33 | */ 34 | @Getter 35 | @Setter 36 | public class SnapshotInfo { 37 | 38 | // Type of snapshot data: true for PUBKEY, false for BLOCK_DATA 39 | protected boolean type; 40 | // The actual data - either block data or public key 41 | protected byte[] data; 42 | 43 | /** 44 | * Default constructor 45 | */ 46 | public SnapshotInfo() { 47 | } 48 | 49 | /** 50 | * Constructor with type and data 51 | * @param type Type of data (true=PUBKEY, false=BLOCK_DATA) 52 | * @param data The snapshot data 53 | */ 54 | public SnapshotInfo(boolean type, byte[] data) { 55 | this.type = type; 56 | this.data = data; 57 | } 58 | 59 | /** 60 | * Get the type of snapshot data 61 | * @return true for PUBKEY, false for BLOCK_DATA 62 | */ 63 | public boolean getType() { 64 | return type; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "SnapshotInfo{" + 70 | "type=" + type + 71 | ", data=" + Arrays.toString(data) + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/NodeManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net; 25 | 26 | import static org.junit.Assert.assertTrue; 27 | 28 | import io.xdag.config.Config; 29 | import io.xdag.config.DevnetConfig; 30 | 31 | import java.net.InetSocketAddress; 32 | import java.util.List; 33 | 34 | import org.junit.Before; 35 | import org.junit.Test; 36 | 37 | import com.google.common.collect.Lists; 38 | 39 | public class NodeManagerTest { 40 | 41 | Config config = new DevnetConfig(); 42 | 43 | @Before 44 | public void setUp() throws Exception { 45 | String[] list = new String[]{"127.0.0.1:1001", "127.0.0.1:1002"}; 46 | List addressList = Lists.newArrayList(); 47 | for (String address : list) { 48 | InetSocketAddress inetSocketAddress = new InetSocketAddress(address.split(":")[0],Integer.parseInt(address.split(":")[1])); 49 | addressList.add(inetSocketAddress); 50 | } 51 | config.getNodeSpec().setWhiteIPList(addressList); 52 | } 53 | 54 | @Test 55 | public void testWhiteList() { 56 | NetDBManager netDBMgr = new NetDBManager(this.config); 57 | netDBMgr.start(); 58 | assertTrue(netDBMgr.canAccept(new InetSocketAddress("127.0.0.1",1001))); 59 | assertTrue(netDBMgr.canAccept(new InetSocketAddress("127.0.0.1",1002))); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/response/BlockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.rpc.model.response; 26 | 27 | import java.util.List; 28 | import lombok.Builder; 29 | import lombok.Data; 30 | 31 | @Data 32 | @Builder 33 | public class BlockResponse { 34 | 35 | private long height; 36 | private String balance; 37 | private long blockTime; 38 | private long timeStamp; // xdagTime 39 | private String state; 40 | private String hash; 41 | private String address; 42 | private String remark; 43 | private String diff; 44 | private String type; 45 | private String flags; 46 | private int totalPage; 47 | private List refs; // means all the ref block 48 | private List transactions; // means transaction a wallet have 49 | 50 | 51 | @Data 52 | @Builder 53 | public static class TxLink { 54 | private int direction; // 0 input 1 output 2 earning 55 | private String hashlow; 56 | private String address; 57 | private String amount; 58 | private long time; 59 | private String remark; 60 | } 61 | 62 | @Data 63 | @Builder 64 | public static class Link { 65 | private int direction; // 0 input 1 output 2 fee 66 | private String address; 67 | private String hashlow; 68 | private String amount; 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/model/request/TransactionRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.model.request; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | import lombok.Getter; 29 | import lombok.NoArgsConstructor; 30 | import lombok.Setter; 31 | 32 | @Getter 33 | @Setter 34 | @NoArgsConstructor // Add this annotation for default constructor 35 | public class TransactionRequest { 36 | @JsonProperty("from") 37 | private String from; // Change to private for better encapsulation 38 | 39 | @JsonProperty("to") 40 | private String to; 41 | 42 | @JsonProperty("value") 43 | private String value; 44 | 45 | @JsonProperty("remark") 46 | private String remark; 47 | 48 | @JsonProperty("nonce") 49 | private String nonce; 50 | 51 | // Add all-args constructor with JsonCreator 52 | @JsonCreator 53 | public TransactionRequest( 54 | @JsonProperty("from") String from, 55 | @JsonProperty("to") String to, 56 | @JsonProperty("value") String value, 57 | @JsonProperty("remark") String remark, 58 | @JsonProperty("nonce") String nonce) { 59 | this.from = from; 60 | this.to = to; 61 | this.value = value; 62 | this.remark = remark; 63 | this.nonce = nonce; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/assembly/distribution.xml: -------------------------------------------------------------------------------- 1 | 4 | distribution 5 | 6 | zip 7 | 8 | 9 | true 10 | xdagj-${project.version} 11 | 12 | 13 | 14 | 15 | ${project.build.directory} 16 | / 17 | 18 | xdagj-${project.version}-executable.jar 19 | 20 | 0644 21 | 22 | 23 | 24 | src/main/resources 25 | / 26 | 27 | log4j2.xml 28 | xdag-mainnet.conf 29 | xdag-testnet.conf 30 | xdag-devnet.conf 31 | druid.properties 32 | 33 | 0644 34 | 35 | 36 | 37 | ${project.build.directory}/filtered-scripts 38 | / 39 | 40 | xdag.bat 41 | 42 | 0644 43 | 44 | 45 | ${project.build.directory}/filtered-scripts 46 | / 47 | 48 | xdag.sh 49 | 50 | 0755 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/FrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | import org.junit.Test; 29 | 30 | import io.netty.buffer.ByteBuf; 31 | import io.netty.buffer.Unpooled; 32 | 33 | public class FrameTest { 34 | 35 | @Test 36 | public void testReadAndWrite() { 37 | short version = 0x1122; 38 | byte compressType = 0x33; 39 | byte packetType = 0x44; 40 | int packetId = 0x55667788; 41 | int packetSize = 0x99aabbcc; 42 | int bodySize = 0xddeeff00; 43 | Frame frame = new Frame(version, compressType, packetType, packetId, packetSize, bodySize, null); 44 | 45 | ByteBuf buf = Unpooled.copiedBuffer(new byte[Frame.HEADER_SIZE]); 46 | 47 | buf.writerIndex(0); 48 | frame.writeHeader(buf); 49 | 50 | buf.readerIndex(0); 51 | Frame frame2 = Frame.readHeader(buf); 52 | 53 | assertEquals(frame.getVersion(), frame2.getVersion()); 54 | assertEquals(frame.getCompressType(), frame2.getCompressType()); 55 | assertEquals(frame.getPacketType(), frame2.getPacketType()); 56 | assertEquals(frame.getPacketId(), frame2.getPacketId()); 57 | assertEquals(frame.getPacketSize(), frame2.getPacketSize()); 58 | assertEquals(frame.getBodySize(), frame2.getBodySize()); 59 | assertEquals(frame.getBody(), frame2.getBody()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/server/protocol/JsonRpcResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.rpc.server.protocol; 25 | 26 | import com.fasterxml.jackson.annotation.JsonInclude; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | import io.xdag.rpc.error.JsonRpcError; 29 | import lombok.Getter; 30 | 31 | @Getter 32 | @JsonInclude(JsonInclude.Include.NON_NULL) 33 | public class JsonRpcResponse { 34 | // Getters and Setters 35 | @JsonProperty("jsonrpc") 36 | private String jsonrpc = "2.0"; 37 | 38 | @JsonProperty("id") 39 | private int id; 40 | 41 | @JsonProperty("result") 42 | private Object result; 43 | 44 | 45 | public JsonRpcResponse(int id, Object result) { 46 | this.id = id; 47 | this.result = result; 48 | } 49 | 50 | /** 51 | * Creates a success response 52 | * @param id the request id 53 | * @param result the result object 54 | * @return a new JsonRpcResponse with the result 55 | */ 56 | public static JsonRpcResponse success(int id, Object result) { 57 | return new JsonRpcResponse(id, result); 58 | } 59 | 60 | /** 61 | * Creates a notification response (without id) 62 | * @param result the result object 63 | * @return a new JsonRpcResponse without id 64 | */ 65 | public static JsonRpcResponse notification(Object result) { 66 | return new JsonRpcResponse(1, result); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/NewBlockMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.core.Block; 27 | import io.xdag.utils.SimpleEncoder; 28 | import io.xdag.core.XdagBlock; 29 | import io.xdag.net.message.Message; 30 | import io.xdag.net.message.MessageCode; 31 | import io.xdag.utils.SimpleDecoder; 32 | import lombok.Getter; 33 | import lombok.Setter; 34 | 35 | @Getter 36 | @Setter 37 | public class NewBlockMessage extends Message { 38 | 39 | private XdagBlock xdagBlock; 40 | private Block block; 41 | private int ttl; 42 | 43 | public NewBlockMessage(byte[] body) { 44 | super(MessageCode.NEW_BLOCK, null); 45 | 46 | SimpleDecoder dec = new SimpleDecoder(body); 47 | 48 | this.body = dec.readBytes(); 49 | this.xdagBlock = new XdagBlock(this.body); 50 | this.block = new Block(this.xdagBlock); 51 | this.ttl = dec.readInt(); 52 | } 53 | 54 | public NewBlockMessage(Block block, int ttl) { 55 | super(MessageCode.NEW_BLOCK, null); 56 | 57 | this.block = block; 58 | this.ttl = ttl; 59 | 60 | SimpleEncoder enc = encode(); 61 | this.body = enc.toBytes(); 62 | } 63 | 64 | private SimpleEncoder encode() { 65 | SimpleEncoder enc = new SimpleEncoder(); 66 | enc.writeBytes(this.block.toBytes()); 67 | enc.writeInt(ttl); 68 | return enc; 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/consensus/SyncBlockMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.consensus; 25 | 26 | import io.xdag.core.Block; 27 | import io.xdag.utils.SimpleEncoder; 28 | import io.xdag.core.XdagBlock; 29 | import io.xdag.net.message.Message; 30 | import io.xdag.net.message.MessageCode; 31 | import io.xdag.utils.SimpleDecoder; 32 | import lombok.Getter; 33 | import lombok.Setter; 34 | 35 | @Getter 36 | @Setter 37 | public class SyncBlockMessage extends Message { 38 | 39 | private XdagBlock xdagBlock; 40 | private Block block; 41 | private int ttl; 42 | 43 | public SyncBlockMessage(byte[] body) { 44 | super(MessageCode.SYNC_BLOCK, null); 45 | 46 | SimpleDecoder dec = new SimpleDecoder(body); 47 | 48 | this.body = dec.readBytes(); 49 | this.xdagBlock = new XdagBlock(this.body); 50 | this.block = new Block(this.xdagBlock); 51 | this.ttl = dec.readInt(); 52 | } 53 | 54 | public SyncBlockMessage(Block block, int ttl) { 55 | super(MessageCode.SYNC_BLOCK, null); 56 | 57 | this.block = block; 58 | this.ttl = ttl; 59 | 60 | SimpleEncoder enc = encode(); 61 | this.body = enc.toBytes(); 62 | } 63 | 64 | private SimpleEncoder encode() { 65 | SimpleEncoder enc = new SimpleEncoder(); 66 | enc.writeBytes(this.block.toBytes()); 67 | enc.writeInt(ttl); 68 | return enc; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/rpc/server/protocol/JsonRpcRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.rpc.server.protocol; 26 | 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | import io.xdag.rpc.error.JsonRpcException; 29 | import lombok.Getter; 30 | import lombok.Setter; 31 | import org.apache.commons.lang3.StringUtils; 32 | 33 | @Setter 34 | @Getter 35 | public class JsonRpcRequest { 36 | // Getters and Setters 37 | @JsonProperty("jsonrpc") 38 | private String jsonrpc = "2.0"; 39 | 40 | @JsonProperty("method") 41 | private String method; 42 | 43 | @JsonProperty("params") 44 | private Object[] params; 45 | 46 | @JsonProperty("id") 47 | private int id; 48 | 49 | /** 50 | * Validate the JSON-RPC request 51 | * @throws JsonRpcException if the request is invalid 52 | */ 53 | public void validate() throws JsonRpcException { 54 | // Check JSON-RPC version 55 | if (StringUtils.isBlank(jsonrpc) || !jsonrpc.equals("2.0")) { 56 | throw JsonRpcException.invalidRequest("Invalid JSON-RPC version, must be '2.0'"); 57 | } 58 | 59 | // Check method 60 | if (StringUtils.isBlank(method)) { 61 | throw JsonRpcException.invalidRequest("Method cannot be null or empty"); 62 | } 63 | 64 | // ID can be any valid JSON value or null according to JSON-RPC 2.0 spec 65 | // No validation needed for id 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/rocksdb/RocksdbFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.db.rocksdb; 26 | 27 | import io.xdag.config.Config; 28 | import java.util.EnumMap; 29 | import org.apache.commons.lang3.StringUtils; 30 | 31 | public class RocksdbFactory implements DatabaseFactory { 32 | 33 | private final EnumMap> databases = new EnumMap<>(DatabaseName.class); 34 | 35 | protected Config config; 36 | 37 | public RocksdbFactory(Config config) { 38 | this.config = config; 39 | } 40 | 41 | @Override 42 | public KVSource getDB(DatabaseName name) { 43 | return databases.computeIfAbsent( 44 | name, k -> { 45 | RocksdbKVSource dataSource; 46 | // time data source must set fixed prefix length 47 | if (StringUtils.equals(DatabaseName.TIME.toString(), name.toString())) { 48 | dataSource = new RocksdbKVSource(name.toString(), 9); 49 | } else { 50 | dataSource = new RocksdbKVSource(name.toString()); 51 | } 52 | dataSource.setConfig(config); 53 | return dataSource; 54 | }); 55 | } 56 | 57 | @Override 58 | public void close() { 59 | for (KVSource db : databases.values()) { 60 | db.close(); 61 | } 62 | databases.clear(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/core/ImportResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.core; 26 | 27 | import org.apache.tuweni.bytes.MutableBytes32; 28 | 29 | import lombok.Getter; 30 | import lombok.Setter; 31 | 32 | /** 33 | * Enum representing different results of block import operations 34 | * ERROR - Import failed with error 35 | * EXIST - Block already exists 36 | * NO_PARENT - Parent block not found 37 | * INVALID_BLOCK - Block validation failed 38 | * IN_MEM - Block is already in memory 39 | * IMPORTED_EXTRA - Block imported as extra 40 | * IMPORTED_NOT_BEST - Block imported but not in main chain 41 | * IMPORTED_BEST - Block imported into main chain 42 | */ 43 | public enum ImportResult { 44 | ERROR, 45 | EXIST, 46 | NO_PARENT, 47 | INVALID_BLOCK, 48 | IN_MEM, 49 | 50 | IMPORTED_EXTRA, 51 | IMPORTED_NOT_BEST, 52 | IMPORTED_BEST; 53 | 54 | // Truncated hash of the block 55 | private MutableBytes32 hashLow; 56 | 57 | // Error message if import failed 58 | @Setter 59 | @Getter 60 | private String errorInfo; 61 | 62 | /** 63 | * Get the truncated hash of the block 64 | * @return The truncated hash as MutableBytes32 65 | */ 66 | public MutableBytes32 getHashlow() { 67 | return hashLow; 68 | } 69 | 70 | /** 71 | * Set the truncated hash of the block 72 | * @param hashLow The truncated hash to set 73 | */ 74 | public void setHashlow(MutableBytes32 hashLow) { 75 | this.hashLow = hashLow; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/net/ChannelManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.net; 26 | 27 | import static org.junit.Assert.assertTrue; 28 | 29 | import io.xdag.Kernel; 30 | import io.xdag.config.Config; 31 | import io.xdag.config.DevnetConfig; 32 | import io.xdag.crypto.SampleKeys; 33 | import io.xdag.crypto.Sign; 34 | 35 | import java.net.InetSocketAddress; 36 | import java.util.List; 37 | 38 | import org.hyperledger.besu.crypto.KeyPair; 39 | import org.junit.Before; 40 | import org.junit.Test; 41 | 42 | import com.google.common.collect.Lists; 43 | 44 | public class ChannelManagerTest { 45 | 46 | Config config = new DevnetConfig(); 47 | Kernel kernel; 48 | 49 | @Before 50 | public void setUp() throws Exception { 51 | String[] list = new String[]{"127.0.0.1:1001", "127.0.0.1:1002"}; 52 | List addressList = Lists.newArrayList(); 53 | for (String address : list) { 54 | addressList.add(new InetSocketAddress(address.split(":")[0],Integer.parseInt(address.split(":")[1]))); 55 | } 56 | config.getNodeSpec().setWhiteIPList(addressList); 57 | KeyPair key = KeyPair.create(SampleKeys.SRIVATE_KEY, Sign.CURVE, Sign.CURVE_NAME); 58 | kernel = new Kernel(config, key); 59 | } 60 | 61 | @Test 62 | public void testIp() { 63 | ChannelManager channelManager = new ChannelManager(kernel); 64 | InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 1001); 65 | assertTrue(channelManager.isAcceptable(inetSocketAddress)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/db/AddressStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.db; 25 | 26 | import io.xdag.core.XdagLifecycle; 27 | import org.apache.tuweni.units.bigints.UInt64; 28 | 29 | import io.xdag.core.XAmount; 30 | 31 | public interface AddressStore extends XdagLifecycle { 32 | 33 | byte ADDRESS_SIZE = (byte) 0x10; 34 | byte AMOUNT_SUM = (byte) 0x20; 35 | byte ADDRESS = (byte) 0x30; 36 | byte CURRENT_TRANSACTION_QUANTITY = (byte) 0x40; 37 | byte EXECUTED_NONCE_NUM = (byte) 0x50; 38 | 39 | void reset(); 40 | 41 | XAmount getBalanceByAddress(byte[] Address); 42 | 43 | boolean addressIsExist(byte[] Address); 44 | 45 | void addAddress(byte[] Address); 46 | 47 | XAmount getAllBalance(); 48 | 49 | void saveAddressSize(byte[] addressSize); 50 | 51 | void saveAmountSum(XAmount balanceSum); 52 | 53 | void updateAllBalance(XAmount balance); 54 | 55 | UInt64 getAddressSize(); 56 | 57 | void updateBalance(byte[] address, XAmount balance); 58 | 59 | void snapshotAddress(byte[] address, XAmount balance); 60 | 61 | void snapshotTxQuantity(byte[] address, UInt64 txQuantity); 62 | 63 | void snapshotExeTxNonceNum(byte[] address, UInt64 exeTxNonceNum); 64 | 65 | UInt64 getTxQuantity(byte[] address); 66 | 67 | void updateTxQuantity(byte[] address, UInt64 newTxQuantity); 68 | 69 | void updateTxQuantity(byte[] address, UInt64 currentTxNonce, UInt64 currentExeNonce); 70 | 71 | UInt64 getExecutedNonceNum(byte[] address); 72 | 73 | void updateExcutedNonceNum(byte[] address,boolean addOrSubstract); 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/MainnetConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD; 28 | 29 | import org.apache.tuweni.units.bigints.UInt64; 30 | 31 | import io.xdag.Network; 32 | import io.xdag.core.XAmount; 33 | 34 | /** 35 | * Configuration class for the main network (mainnet) 36 | * Extends AbstractConfig to provide mainnet-specific settings 37 | */ 38 | public class MainnetConfig extends AbstractConfig { 39 | 40 | /** 41 | * Constructor initializes mainnet configuration with specific parameters: 42 | * - Network type: MAINNET 43 | * - Version: MAINNET_VERSION 44 | * - XDAG era: 0x16940000000L 45 | * - Main start amount: 2^42 XDAG 46 | * - Apollo fork height: 1017323 47 | * - Apollo fork amount: 2^39 XDAG 48 | * - Field header type: XDAG_FIELD_HEAD 49 | * - Wallet file paths for mainnet 50 | */ 51 | public MainnetConfig() { 52 | super("mainnet", "xdag-mainnet", Network.MAINNET, Constants.MAINNET_VERSION); 53 | this.network = Network.MAINNET; 54 | this.xdagEra = 0x16940000000L; 55 | this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong()); 56 | this.apolloForkHeight = 1017323; 57 | this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong()); 58 | this.xdagFieldHeader = XDAG_FIELD_HEAD; 59 | this.walletKeyFile = this.rootDir + "/wallet.dat"; 60 | this.walletFilePath = this.rootDir + "/wallet/" + Constants.WALLET_FILE_NAME; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/message/p2p/InitMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package io.xdag.net.message.p2p; 25 | 26 | import io.xdag.utils.SimpleEncoder; 27 | import io.xdag.net.message.Message; 28 | import io.xdag.net.message.MessageCode; 29 | import io.xdag.utils.BytesUtils; 30 | import io.xdag.utils.SimpleDecoder; 31 | import lombok.Getter; 32 | 33 | @Getter 34 | public class InitMessage extends Message { 35 | 36 | public static final int SECRET_LENGTH = 32; 37 | 38 | private final byte[] secret; 39 | private final long timestamp; 40 | 41 | public InitMessage(byte[] secret, long timestamp) { 42 | super(MessageCode.HANDSHAKE_INIT, null); 43 | 44 | this.secret = secret; 45 | this.timestamp = timestamp; 46 | 47 | SimpleEncoder enc = new SimpleEncoder(); 48 | enc.writeBytes(secret); 49 | enc.writeLong(timestamp); 50 | 51 | this.body = enc.toBytes(); 52 | } 53 | 54 | public InitMessage(byte[] body) { 55 | super(MessageCode.HANDSHAKE_INIT, null); 56 | 57 | SimpleDecoder dec = new SimpleDecoder(body); 58 | this.secret = dec.readBytes(); 59 | this.timestamp = dec.readLong(); 60 | 61 | this.body = body; 62 | } 63 | 64 | public boolean validate() { 65 | return secret != null && secret.length == SECRET_LENGTH && timestamp > 0; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "InitMessage{" + 71 | "secret=" + BytesUtils.toHexString(secret) + 72 | ", timestamp=" + timestamp + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/TestnetConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST; 28 | 29 | import org.apache.tuweni.units.bigints.UInt64; 30 | 31 | import io.xdag.Network; 32 | import io.xdag.core.XAmount; 33 | 34 | /** 35 | * Configuration class for the test network (testnet) 36 | * Extends AbstractConfig to provide testnet-specific settings 37 | */ 38 | public class TestnetConfig extends AbstractConfig { 39 | 40 | /** 41 | * Constructor initializes testnet configuration with specific parameters: 42 | * - Network type: TESTNET 43 | * - Version: TESTNET_VERSION 44 | * - Wait epoch: 1 45 | * - XDAG era: 0x16900000000L 46 | * - Main start amount: 2^42 XDAG 47 | * - Apollo fork height: 196250 48 | * - Apollo fork amount: 2^39 XDAG 49 | * - Field header type: XDAG_FIELD_HEAD_TEST 50 | * - Wallet file paths for testnet 51 | */ 52 | public TestnetConfig() { 53 | super("testnet", "xdag-testnet", Network.TESTNET, Constants.TESTNET_VERSION); 54 | this.waitEpoch = 1; 55 | this.xdagEra = 0x16900000000L; 56 | this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong()); 57 | this.apolloForkHeight = 196250; 58 | this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong()); 59 | this.xdagFieldHeader = XDAG_FIELD_HEAD_TEST; 60 | this.walletKeyFile = this.rootDir + "/wallet-testnet.dat"; 61 | this.walletFilePath = this.rootDir + "/wallet/" + Constants.WALLET_FILE_NAME; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.utils; 26 | 27 | import com.google.common.collect.Lists; 28 | import io.xdag.db.BlockStore; 29 | import java.util.List; 30 | import org.bouncycastle.util.encoders.Hex; 31 | 32 | /** 33 | * Utility class for file operations 34 | */ 35 | public class FileUtils { 36 | 37 | /** 38 | * Generates a list of hierarchical file paths based on a timestamp 39 | * 40 | * The method creates a directory structure by extracting bytes from the timestamp 41 | * and converting them to hex strings. Each level represents 8 bits of the timestamp. 42 | * 43 | * @param time The timestamp to generate paths from 44 | * @return A list of file paths, including intermediate paths 45 | */ 46 | public static List getFileName(long time) { 47 | List files = Lists.newArrayList(BlockStore.SUM_FILE_NAME); 48 | StringBuilder stringBuffer = new StringBuilder( 49 | Hex.toHexString(BytesUtils.byteToBytes((byte) ((time >> 40) & 0xff), true))); 50 | stringBuffer.append("/"); 51 | files.add(stringBuffer + BlockStore.SUM_FILE_NAME); 52 | stringBuffer.append(Hex.toHexString(BytesUtils.byteToBytes((byte) ((time >> 32) & 0xff), true))); 53 | stringBuffer.append("/"); 54 | files.add(stringBuffer + BlockStore.SUM_FILE_NAME); 55 | stringBuffer.append(Hex.toHexString(BytesUtils.byteToBytes((byte) ((time >> 24) & 0xff), true))); 56 | stringBuffer.append("/"); 57 | files.add(stringBuffer + BlockStore.SUM_FILE_NAME); 58 | return files; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/config/DevnetConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.config; 26 | 27 | import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST; 28 | 29 | import org.apache.tuweni.units.bigints.UInt64; 30 | 31 | import io.xdag.Network; 32 | import io.xdag.core.XAmount; 33 | 34 | /** 35 | * Configuration class for the development network (devnet) 36 | * Extends AbstractConfig to provide devnet-specific settings 37 | */ 38 | public class DevnetConfig extends AbstractConfig { 39 | 40 | /** 41 | * Constructor initializes devnet configuration with specific parameters: 42 | * - Network type: DEVNET 43 | * - Version: DEVNET_VERSION 44 | * - Empty whitelist URL 45 | * - Wait epoch: 1 46 | * - XDAG era: 0x16900000000L 47 | * - Main start amount: 2^42 XDAG 48 | * - Apollo fork height: 1000 49 | * - Apollo fork amount: 2^39 XDAG 50 | * - Field header type: XDAG_FIELD_HEAD_TEST 51 | * - Wallet file paths for testnet 52 | */ 53 | public DevnetConfig() { 54 | super("devnet", "xdag-devnet", Network.DEVNET, Constants.DEVNET_VERSION); 55 | this.waitEpoch = 1; 56 | this.xdagEra = 0x16900000000L; 57 | this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong()); 58 | this.apolloForkHeight = 1000; 59 | this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong()); 60 | this.xdagFieldHeader = XDAG_FIELD_HEAD_TEST; 61 | this.walletKeyFile = this.rootDir + "/wallet-devnet.dat"; 62 | this.walletFilePath = this.rootDir + "/wallet/" + Constants.WALLET_FILE_NAME; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/xdag/net/NetDBManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.net; 26 | 27 | import io.xdag.config.Config; 28 | import java.net.InetSocketAddress; 29 | 30 | import io.xdag.core.AbstractXdagLifecycle; 31 | import lombok.Getter; 32 | import lombok.extern.slf4j.Slf4j; 33 | 34 | /** 35 | * Manages the network database including whitelisted nodes 36 | */ 37 | @Getter 38 | @Slf4j 39 | public class NetDBManager extends AbstractXdagLifecycle { 40 | private final String database; 41 | private final String databaseWhite; 42 | private final NetDB whiteDB; 43 | private final Config config; 44 | 45 | /** 46 | * Constructor initializes database paths and network DBs 47 | */ 48 | public NetDBManager(Config config) { 49 | this.config = config; 50 | database = config.getNodeSpec().getNetDBDir(); 51 | databaseWhite = config.getNodeSpec().getWhiteListDir(); 52 | whiteDB = new NetDB(); 53 | } 54 | 55 | /** 56 | * Load whitelist IPs from config 57 | */ 58 | public void loadFromConfig() { 59 | for (InetSocketAddress address:config.getNodeSpec().getWhiteIPList()){ 60 | whiteDB.addNewIP(address); 61 | } 62 | } 63 | 64 | /** 65 | * Initialize network database 66 | */ 67 | @Override 68 | protected void doStart() { 69 | loadFromConfig(); 70 | } 71 | 72 | @Override 73 | protected void doStop() { 74 | } 75 | 76 | /** 77 | * Check if address is whitelisted 78 | */ 79 | public boolean canAccept(InetSocketAddress address) { 80 | return whiteDB.contains(address); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/io/xdag/core/MintTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2030 The XdagJ Developers 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package io.xdag.core; 26 | 27 | import static io.xdag.config.Constants.MAIN_BIG_PERIOD_LOG; 28 | import static io.xdag.utils.BasicUtils.xdag2amount; 29 | import static org.junit.Assert.assertEquals; 30 | 31 | import io.xdag.config.Config; 32 | import io.xdag.config.DevnetConfig; 33 | import org.junit.Test; 34 | 35 | public class MintTest { 36 | 37 | Config config = new DevnetConfig(); 38 | 39 | @Test 40 | public void testMint() { 41 | // 每四年减半 大致就是增加了 2097152个块 42 | int num = 1017323 + 2097152; 43 | long reward = getCurrentReward(); 44 | XAmount reward1 = getReward(0, num); 45 | 46 | assertEquals(4398046511104L, reward); 47 | assertEquals(274877906944L, reward1.toDecimal(0, XUnit.NANO_XDAG).longValue()); 48 | } 49 | 50 | /** 51 | * 根据当前区块数量计算奖励金额 cheato * 52 | */ 53 | public long getCurrentReward() { 54 | return xdag2amount(1024).toLong(); 55 | } 56 | 57 | public XAmount getReward(long time, long num) { 58 | XAmount start = getStartAmount(time, num); 59 | long nanoStart = start.toXAmount().toLong(); 60 | return XAmount.of(nanoStart >> (num >> MAIN_BIG_PERIOD_LOG)); 61 | } 62 | 63 | private XAmount getStartAmount(long time, long num) { 64 | long forkHeight = config.getApolloForkHeight(); 65 | XAmount startAmount; 66 | if (num >= forkHeight) { 67 | startAmount = config.getApolloForkAmount(); 68 | } else { 69 | startAmount = config.getMainStartAmount(); 70 | } 71 | 72 | return startAmount; 73 | } 74 | } 75 | --------------------------------------------------------------------------------