-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
47576a4
commit 20c837d
Showing
50 changed files
with
2,119 additions
and
180 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
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
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
68 changes: 68 additions & 0 deletions
68
concordium-sdk-examples/src/main/java/com/concordium/sdk/examples/Cis2.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,68 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.cis2.BalanceQuery; | ||
import com.concordium.sdk.cis2.Cis2Client; | ||
import com.concordium.sdk.cis2.TokenAmount; | ||
import com.concordium.sdk.cis2.TokenId; | ||
import com.concordium.sdk.exceptions.ClientInitializationException; | ||
import com.concordium.sdk.requests.BlockQuery; | ||
import com.concordium.sdk.transactions.Hash; | ||
import com.concordium.sdk.types.AbstractAddress; | ||
import com.concordium.sdk.types.AccountAddress; | ||
import com.concordium.sdk.types.ContractAddress; | ||
import lombok.val; | ||
import picocli.CommandLine; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Example usage of the CIS2 client | ||
*/ | ||
@CommandLine.Command(name = "Cis2", mixinStandardHelpOptions = true) | ||
public class Cis2 implements Callable<Integer> { | ||
|
||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20000") | ||
private String endpoint; | ||
|
||
@CommandLine.Option( | ||
names = {"--index"}, | ||
description = "Index of the contract.", | ||
defaultValue = "9390") | ||
private long contractIndex; | ||
|
||
@Override | ||
public Integer call() throws ClientInitializationException, MalformedURLException { | ||
URL endpointUrl = new URL(this.endpoint); | ||
val client = Cis2Client.newClient(ClientV2.from(Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build()), ContractAddress.from(contractIndex, 0)); | ||
|
||
val eventsForBlock = client.getEventsFor(BlockQuery.HASH(Hash.from("cfd9a3de1b7de2d2942f80b102135bcc8553f472c53c6c8074110aba38bca43c"))); | ||
while (eventsForBlock.hasNext()) { | ||
System.out.println(eventsForBlock.next()); | ||
} | ||
|
||
val balances = client.balanceOf(new BalanceQuery(TokenId.min(), AccountAddress.from("3rXssmPErqhHvDMByFLCEydYAJwot7ZkL7xcu8y296iMJxwNGC"))); | ||
for (BalanceQuery balanceQuery : balances.keySet()) { | ||
TokenId tokenId = balanceQuery.getTokenId(); | ||
AbstractAddress owner = balanceQuery.getAddress(); | ||
TokenAmount balance = balances.get(balanceQuery); | ||
System.out.println("TokenId: " + tokenId + " Owner: " + owner + " Balance " + balance); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new Cis2()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
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
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
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
32 changes: 32 additions & 0 deletions
32
concordium-sdk/src/main/java/com/concordium/sdk/cis2/BalanceQuery.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,32 @@ | ||
package com.concordium.sdk.cis2; | ||
|
||
import com.concordium.sdk.types.AbstractAddress; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* An object used for querying token balances. | ||
* See <a href="https://proposals.concordium.software/CIS/cis-2.html#balanceof">here</a> for the specification. | ||
*/ | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public class BalanceQuery { | ||
|
||
/** | ||
* The token id to query | ||
*/ | ||
private final TokenId tokenId; | ||
|
||
/** | ||
* The address to query the balance of | ||
*/ | ||
private final AbstractAddress address; | ||
|
||
public BalanceQuery(TokenId tokenId, AbstractAddress address) { | ||
this.tokenId = tokenId; | ||
this.address = address; | ||
} | ||
|
||
} |
Oops, something went wrong.