-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5bc8980
Showing
7 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
--- | ||
|
||
### **`LICENSE`** | ||
```text | ||
MIT License | ||
|
||
Copyright (c) 2024 Paylink Protocol | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# PayLink Protocol Library | ||
|
||
A Java library for interacting with the PayLink Protocol on Ethereum. | ||
|
||
## Features | ||
|
||
- Subscribe to PayLink Protocol events | ||
- Decode event data into Java objects | ||
- Works with any Ethereum-compatible RPC endpoint | ||
|
||
## Installation | ||
|
||
Download the latest .JAR via our GitHub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'com.github.johnrengelman.shadow' version '8.1.1' | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
shadowJar { | ||
archiveBaseName.set('PayLinkProtocol-Core') | ||
archiveClassifier.set('') | ||
archiveVersion.set('') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Main-Class': 'com.crypto.paylinkprotocol.examples.Basic' | ||
} | ||
} | ||
|
||
dependencies { | ||
api 'org.web3j:core:4.9.5' | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/crypto/paylinkprotocol/examples/Basic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.crypto.paylinkprotocol.examples; | ||
|
||
import com.crypto.paylinkprotocol.manager.PayLinkProtocolManager; | ||
|
||
import io.reactivex.disposables.Disposable; | ||
|
||
public class Basic { | ||
|
||
public static void main(String[] args) { | ||
PayLinkProtocolManager payLinkProtocolManager = new PayLinkProtocolManager( | ||
"", | ||
0); | ||
Disposable disposable = payLinkProtocolManager.subscribe().subscribe(System.out::println, Throwable::printStackTrace); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/crypto/paylinkprotocol/manager/PayLinkProtocolManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.crypto.paylinkprotocol.manager; | ||
|
||
import com.crypto.paylinkprotocol.model.Event; | ||
import com.crypto.paylinkprotocol.resources.Finals; | ||
|
||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.core.DefaultBlockParameterName; | ||
import org.web3j.protocol.core.methods.request.EthFilter; | ||
import org.web3j.protocol.http.HttpService; | ||
import org.web3j.utils.Numeric; | ||
|
||
import java.math.BigInteger; | ||
|
||
import io.reactivex.Flowable; | ||
|
||
public class PayLinkProtocolManager { | ||
|
||
// Dependencies | ||
private final long appId; | ||
|
||
// Runtime | ||
private final Web3j web3j; | ||
|
||
public PayLinkProtocolManager(String rpcUrl, long appId) { | ||
this.appId = appId; | ||
this.web3j = Web3j.build(new HttpService(rpcUrl)); | ||
} | ||
|
||
public PayLinkProtocolManager(long appId) { | ||
this("https://ethereum-rpc.publicnode.com", appId); | ||
} | ||
|
||
public Flowable<Event> subscribe() { | ||
final EthFilter filter = new EthFilter(DefaultBlockParameterName.SAFE, DefaultBlockParameterName.LATEST, Finals.PLP_ROUTER_ADDRESS); | ||
filter.addSingleTopic(Finals.PLP_PURCHASE_TOPIC); | ||
filter.addSingleTopic(Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(appId), 64)); | ||
return web3j.ethLogFlowable(filter).switchMap(log -> { | ||
try { | ||
final String logData = Numeric.cleanHexPrefix(log.getData()); | ||
final String purchasedToken = Numeric.toHexStringWithPrefix(Numeric.toBigInt(log.getTopics().get(2))); | ||
final long userId = Numeric.toBigInt(logData.substring(0, 64)).longValue(); | ||
final BigInteger purchaseAmount = Numeric.toBigInt(logData.substring(64, (64 * 2))); | ||
final String customerUserAddress = Numeric.toHexStringWithPrefix(Numeric.toBigInt(logData.substring((64 * 2), (64 * 3)))); | ||
return Flowable.just(new Event(appId, purchasedToken, purchaseAmount, userId, customerUserAddress)); | ||
} catch (Exception ex) { | ||
return Flowable.error(ex); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.crypto.paylinkprotocol.model; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class Event { | ||
private long appId; | ||
private String purchasedToken; | ||
private BigInteger purchaseAmount; | ||
private long customerUserId; | ||
private String customerUserAddress; | ||
|
||
public Event() { | ||
} | ||
|
||
public Event(long appId, String purchasedToken, BigInteger purchaseAmount, long customerUserId, String customerUserAddress) { | ||
this.appId = appId; | ||
this.purchasedToken = purchasedToken; | ||
this.purchaseAmount = purchaseAmount; | ||
this.customerUserId = customerUserId; | ||
this.customerUserAddress = customerUserAddress; | ||
} | ||
|
||
public long getAppId() { | ||
return appId; | ||
} | ||
|
||
public void setAppId(long appId) { | ||
this.appId = appId; | ||
} | ||
|
||
public String getPurchasedToken() { | ||
return purchasedToken; | ||
} | ||
|
||
public void setPurchasedToken(String purchasedToken) { | ||
this.purchasedToken = purchasedToken; | ||
} | ||
|
||
public BigInteger getPurchaseAmount() { | ||
return purchaseAmount; | ||
} | ||
|
||
public void setPurchaseAmount(BigInteger purchaseAmount) { | ||
this.purchaseAmount = purchaseAmount; | ||
} | ||
|
||
public long getCustomerUserId() { | ||
return customerUserId; | ||
} | ||
|
||
public void setCustomerUserId(long customerUserId) { | ||
this.customerUserId = customerUserId; | ||
} | ||
|
||
public String getCustomerUserAddress() { | ||
return customerUserAddress; | ||
} | ||
|
||
public void setCustomerUserAddress(String customerUserAddress) { | ||
this.customerUserAddress = customerUserAddress; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Event{" + | ||
"appId=" + appId + | ||
", purchasedToken='" + purchasedToken + '\'' + | ||
", purchaseAmount=" + purchaseAmount + | ||
", customerUserId=" + customerUserId + | ||
", customerUserAddress='" + customerUserAddress + '\'' + | ||
'}'; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/crypto/paylinkprotocol/resources/Finals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.crypto.paylinkprotocol.resources; | ||
|
||
public class Finals { | ||
public final static String PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827"; | ||
public final static String PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87"; | ||
} |