diff --git a/README.md b/README.md index 98cd7e9..1c35d25 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ upcoming TestNet launch. ## Using -The latest 0.4.2 version tested with sui devnet-0.24.0 version. +The latest 0.4.3 version tested with sui devnet-0.24.0 version. ### Maven @@ -27,7 +27,7 @@ The latest 0.4.2 version tested with sui devnet-0.24.0 version. me.grapebaba sui4j -0.4.2 +0.4.3 ``` @@ -35,7 +35,7 @@ The latest 0.4.2 version tested with sui devnet-0.24.0 version. ```groovy // https://mvnrepository.com/artifact/me.grapebaba/sui4j -implementation 'me.grapebaba:sui4j:0.4.2' +implementation 'me.grapebaba:sui4j:0.4.3' ``` ## Building Locally @@ -70,10 +70,7 @@ doc. ``` git clone git@github.com:MystenLabs/sui.git cd sui -cargo build --release -cd sui/target/release -./sui genesis -./sui start +RUST_LOG="consensus=off" cargo run --bin sui-test-validator ``` #### To run Integration tests @@ -82,104 +79,133 @@ cd sui/target/release ./gradlew integrationTest ``` -## Supported APIs (sui SDK 0.25.0) - -- [x] sui_batchTransaction -- [ ] sui_devInspectTransaction -- [x] sui_dryRunTransaction -- [x] sui_executeTransaction -- [x] sui_executeTransactionSerializedSig(same with sui_executeTransaction) -- [x] sui_getAllBalances -- [x] sui_getAllCoins -- [x] sui_getBalance -- [x] sui_getCheckpointContents -- [x] sui_getCheckpointContentsByDigest -- [x] sui_getCheckpointSummary -- [x] sui_getCheckpointSummaryByDigest -- [x] sui_getCoinMetadata -- [x] sui_getCoins -- [x] sui_getCommitteeInfo -- [ ] sui_getDelegatedStakes -- [ ] sui_getDynamicFieldObject -- [ ] sui_getDynamicFields -- [x] sui_getEvents -- [ ] sui_getLatestCheckpointSequenceNumber -- [x] sui_getMoveFunctionArgTypes -- [x] sui_getNormalizedMoveFunction -- [x] sui_getNormalizedMoveModule -- [x] sui_getNormalizedMoveModulesByPackage -- [x] sui_getNormalizedMoveStruct -- [x] sui_getObject -- [x] sui_getObjectsOwnedByAddress -- [x] sui_getObjectsOwnedByObject -- [x] sui_getRawObject -- [x] sui_getReferenceGasPrice -- [x] sui_getSuiSystemState -- [ ] sui_getTotalSupply -- [x] sui_getTotalTransactionNumber -- [x] sui_getTransaction -- [ ] sui_getTransactionAuthSigners -- [x] sui_getTransactions -- [x] sui_getTransactionsInRange -- [ ] sui_getValidators -- [x] sui_mergeCoins -- [x] sui_moveCall -- [x] sui_pay -- [x] sui_payAllSui -- [x] sui_paySui -- [x] sui_publish -- [ ] sui_requestAddDelegation -- [ ] sui_requestSwitchDelegation -- [ ] sui_requestWithdrawDelegation -- [x] sui_splitCoin -- [x] sui_splitCoinEqual -- [x] sui_subscribeEvent -- [ ] sui_tblsSignRandomnessObject -- [x] sui_transferObject -- [x] sui_transferSui -- [x] sui_tryGetPastObject - - -## Examples +## How to use it +- local-fullnode:http://127.0.0.1:9000 +- local-faucet:http://localhost:9123 +- devnet-fullnode:https://fullnode.devnet.sui.io +- devnet-faucet:https://faucet.devnet.sui.io + +### Connecting to Sui Network +```java +Sui sui = new Sui("","",""); +``` + +### New Address +```java +KeyResponse keyRes = sui.newAddress(SignatureScheme.ED25519); +``` + +### Request Faucet +```java +CompletableFuture faucetRes = sui.requestSuiFromFaucet(s); +``` + +### Writing APIs + +#### Move Call ```java - String BASE_URL="http://localhost:9000"; - // It must be a absolute path - String TEST_KEY_STORE_PATH= - System.getProperty("user.home")+"/.sui/sui_config/sui.keystore"; - Sui sui=new Sui(BASE_URL,TEST_KEY_STORE_PATH); - - // query objects - CompletableFuture>res= - sui.getObjectsOwnedByAddress("0xea79464d86786b7a7a63e3f13f798f29f5e65947"); - List objects=res.get(); - String coinObjectId=objects.get(0).getObjectId(); - List addresses=new ArrayList<>(sui.addresses()); - - // Transfer sui - CompletableFuture res1= - sui.transferSui( - "0xea79464d86786b7a7a63e3f13f798f29f5e65947", - coinObjectId, - 100L, - addresses.get(0), - 2000L, - ExecuteTransactionRequestType.WaitForLocalExecution); - - CompletableFuture res2= +CompletableFuture callRes = sui.moveCall( - "0xea79464d86786b7a7a63e3f13f798f29f5e65947", - "0x0000000000000000000000000000000000000002", - "devnet_nft", - "mint", - Lists.newArrayList(), - Lists.newArrayList( - "Example NFT", - "An example NFT.", - "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"), - null, - 2000L, - ExecuteTransactionRequestType.WaitForLocalExecution); + "0x0a7421363a1f6a82800f7c9340ac02b5905798cb", + "0x02", + "pay", + "split", + Lists.newArrayList(structType), + Lists.newArrayList("0x4b89576d18d500194f14c935bc8b297a8e1556f3217e5f125ae3d1c0f13408f9", 10000L), + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); +``` + +#### Transfer Object +```java +CompletableFuture res = + sui.transferObjects( + sender.get(), + Lists.newArrayList(objects.get(0).getData().getObjectId()), + recipient.get(), + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); +``` + +#### Publish +```java +CompletableFuture res = + sui.publish( + sender.get(), + Lists.newArrayList( + "oRzrCwYAAAAKAQAUAhQsA0BJBIkBEgWbAWcHggLNAgjPBGAGrwXCAwrxCC0MngnUAQAMAR4B" + + "JAIRAh0CHwIlAiYCJwIoAAACAAABDAAAAwQAAQQHAQAAAgYHAAMCDAEIAQQIBAAFBQwABwcCAAkJ" + + "BwAAFgABAAEcARUBAAEjFBUBAAIpCwwAAwoNAQEIAxoJCgEIBBoSEwAFDgYHAQIGIREBAQwGJREB" + + "AQgHIg4PAAgXBAUBAgkbCxYACwMHAwUIBAgIEAgHAgwBDAkIAggABwgIAAILBQEIAQgHAQgAAQYJ" + + "AAEBAgkABwgIAQgHAQgBAgYIBwcICAELBQEJAAEKAgEIBAMHCwUBCQAKCAQKCAQBBggIAQUBCwUB" + + "CAECCQAFAQcICAEIBgEJAAELAwEJAAEICQVCT0FSUwRCb2FyB0Rpc3BsYXkITWV0YWRhdGEGT3B0" + + "aW9uCVB1Ymxpc2hlcgZTdHJpbmcJVHhDb250ZXh0A1VJRANVcmwMYWRkX211bHRpcGxlA2FnZQVi" + + "b2FycwVidXllcgVjbGFpbQdjcmVhdG9yC2Rlc2NyaXB0aW9uB2Rpc3BsYXkLZHVtbXlfZmllbGQI" + + "ZnVsbF91cmwCaWQHaW1nX3VybARpbml0E2lzX29uZV90aW1lX3dpdG5lc3MIbWV0YWRhdGEEbmFt" + + "ZQNuZXcVbmV3X3Vuc2FmZV9mcm9tX2J5dGVzBG5vbmUGb2JqZWN0Bm9wdGlvbgdwYWNrYWdlBXBy" + + "aWNlD3B1YmxpY190cmFuc2ZlcgZzZW5kZXIEc29tZQZzdHJpbmcIdHJhbnNmZXIKdHhfY29udGV4" + + "dAV0eXBlcwN1cmwEdXRmOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgMI" + + "AAAAAAAAAAAKAgUEbmFtZQoCDAtkZXNjcmlwdGlvbgoCCAdpbWdfdXJsCgIIB2NyZWF0b3IKAgYF" + + "cHJpY2UKAgwLcHJvamVjdF91cmwKAgQDYWdlCgIGBWJ1eWVyCgIJCGZ1bGxfdXJsCgIODWVzY2Fw" + + "ZV9zeW50YXgKAgcGe25hbWV9CgI7OlVuaXF1ZSBCb2FyIGZyb20gdGhlIEJvYXJzIGNvbGxlY3Rp" + + "b24gd2l0aCB7bmFtZX0gYW5kIHtpZH0KAiEgaHR0cHM6Ly9nZXQtYS1ib2FyLmNvbS97aW1nX3Vy" + + "bH0KAgoJe2NyZWF0b3J9CgIIB3twcmljZX0KAhgXaHR0cHM6Ly9nZXQtYS1ib2FyLmNvbS8KAg8O" + + "e21ldGFkYXRhLmFnZX0KAggHe2J1eWVyfQoCCwp7ZnVsbF91cmx9CgIJCFx7bmFtZVx9CgIKCWZp" + + "cnN0LnBuZwoCCwpGaXJzdCBCb2FyCgImJUZpcnN0IEJvYXIgZnJvbSB0aGUgQm9hcnMgY29sbGVj" + + "dGlvbiEKAgYFQ2hyaXMKAiAfaHR0cHM6Ly9nZXQtYS1ib2FyLmZ1bGx1cmwuY29tLwACARIBAQIJ" + + "FAgGFQgEGQgEEAgEDwsDAQgEIAsDAQgEGAgCDQUTCAkCAgELAwAAAAACXw4AOAAEBAUICwEBBwAn" + + "CwAKATgBDAMOAwoBOAIMAg0CBwERAwcCEQMHAxEDBwQRAwcFEQMHBhEDBwcRAwcIEQMHCREDBwoR" + + "A0AMCgAAAAAAAAAHCxEDBwwRAwcNEQMHDhEDBw8RAwcQEQMHEREDBxIRAwcTEQMHFBEDQAwKAAAA" + + "AAAAADgDCwIKAS4RCjgECwMKAS4RCjgFCgERBgcVEQMHFhEDBxcRAwcYEQM4BjgHBgoAAAAAAAAA" + + "EgIKAS4RCgcZEQwSAQsBLhEKOAgCAA=="), + Lists.newArrayList( + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000002"), + null, + 30000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); +``` + +### Reading APIs + +#### Get Owned Objects +```java +CompletableFuture res = + sui.getObjectsOwnedByAddress(sender.get(), null, null, null); +``` + +#### Get Coins +```java +CompletableFuture res = sui.getAllCoins(sender.get(), null, null); +``` + +#### Get Transaction Block +```java +CompletableFuture res = + sui.queryTransactionBlocks(query, null, 10, false); +``` + +### Event APIs + +#### Subscribe +```java +Disposable disposable = + sui.subscribeEvent(eventFilter, System.out::println, System.out::println); + +disposable.dispose(); ``` For more examples, you can see [SuiIntTests](src/integrationTest/java/io/sui/SuiIntTests.java) diff --git a/build.gradle b/build.gradle index 0003f12..2b00a22 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { group 'me.grapebaba' -version '0.4.2' +version '0.4.3' repositories { mavenCentral() diff --git a/docs/address.md b/docs/address.md new file mode 100644 index 0000000..bb4e909 --- /dev/null +++ b/docs/address.md @@ -0,0 +1,17 @@ +## New Address + +### Generate Address + +```java +KeyResponse res1 = sui.newAddress(SignatureScheme.ED25519); + +KeyResponse res2 = sui.newAddress(SignatureScheme.Secp256k1); +``` + +### Request Faucet + +```java +CompletableFuture res = sui.requestSuiFromFaucet(s); +``` + +For more examples, you can see [SuiIntTests](https://github.com/GrapeBaBa/sui4j/blob/main/src/integrationTest/java/io/sui/SuiIntTests.java) diff --git a/docs/call.md b/docs/call.md index b7e7911..1fd8760 100644 --- a/docs/call.md +++ b/docs/call.md @@ -1,56 +1,170 @@ ## Objects and Smart Contract transaction -### TransferObject +### TransferObjects ```java - CompletableFuture res = - sui.transferObject( - "", - "", - "", - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); +TransactionBlockResponseOptions transactionBlockResponseOptions= + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + CompletableFuture res= + sui.transferObjects( + sender.get(), + Lists.newArrayList(objects.get(0).getData().getObjectId()), + recipient.get(), + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); ``` ### Publish ```java - CompletableFuture res = - sui.publish( - "", - [""], - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); +TransactionBlockResponseOptions transactionBlockResponseOptions= + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + CompletableFuture res= + sui.publish( + sender.get(), + Lists.newArrayList( + "oRzrCwYAAAAKAQAUAhQsA0BJBIkBEgWbAWcHggLNAgjPBGAGrwXCAwrxCC0MngnUAQAMAR4B" + +"JAIRAh0CHwIlAiYCJwIoAAACAAABDAAAAwQAAQQHAQAAAgYHAAMCDAEIAQQIBAAFBQwABwcCAAkJ" + +"BwAAFgABAAEcARUBAAEjFBUBAAIpCwwAAwoNAQEIAxoJCgEIBBoSEwAFDgYHAQIGIREBAQwGJREB" + +"AQgHIg4PAAgXBAUBAgkbCxYACwMHAwUIBAgIEAgHAgwBDAkIAggABwgIAAILBQEIAQgHAQgAAQYJ" + +"AAEBAgkABwgIAQgHAQgBAgYIBwcICAELBQEJAAEKAgEIBAMHCwUBCQAKCAQKCAQBBggIAQUBCwUB" + +"CAECCQAFAQcICAEIBgEJAAELAwEJAAEICQVCT0FSUwRCb2FyB0Rpc3BsYXkITWV0YWRhdGEGT3B0" + +"aW9uCVB1Ymxpc2hlcgZTdHJpbmcJVHhDb250ZXh0A1VJRANVcmwMYWRkX211bHRpcGxlA2FnZQVi" + +"b2FycwVidXllcgVjbGFpbQdjcmVhdG9yC2Rlc2NyaXB0aW9uB2Rpc3BsYXkLZHVtbXlfZmllbGQI" + +"ZnVsbF91cmwCaWQHaW1nX3VybARpbml0E2lzX29uZV90aW1lX3dpdG5lc3MIbWV0YWRhdGEEbmFt" + +"ZQNuZXcVbmV3X3Vuc2FmZV9mcm9tX2J5dGVzBG5vbmUGb2JqZWN0Bm9wdGlvbgdwYWNrYWdlBXBy" + +"aWNlD3B1YmxpY190cmFuc2ZlcgZzZW5kZXIEc29tZQZzdHJpbmcIdHJhbnNmZXIKdHhfY29udGV4" + +"dAV0eXBlcwN1cmwEdXRmOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + +"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgMI" + +"AAAAAAAAAAAKAgUEbmFtZQoCDAtkZXNjcmlwdGlvbgoCCAdpbWdfdXJsCgIIB2NyZWF0b3IKAgYF" + +"cHJpY2UKAgwLcHJvamVjdF91cmwKAgQDYWdlCgIGBWJ1eWVyCgIJCGZ1bGxfdXJsCgIODWVzY2Fw" + +"ZV9zeW50YXgKAgcGe25hbWV9CgI7OlVuaXF1ZSBCb2FyIGZyb20gdGhlIEJvYXJzIGNvbGxlY3Rp" + +"b24gd2l0aCB7bmFtZX0gYW5kIHtpZH0KAiEgaHR0cHM6Ly9nZXQtYS1ib2FyLmNvbS97aW1nX3Vy" + +"bH0KAgoJe2NyZWF0b3J9CgIIB3twcmljZX0KAhgXaHR0cHM6Ly9nZXQtYS1ib2FyLmNvbS8KAg8O" + +"e21ldGFkYXRhLmFnZX0KAggHe2J1eWVyfQoCCwp7ZnVsbF91cmx9CgIJCFx7bmFtZVx9CgIKCWZp" + +"cnN0LnBuZwoCCwpGaXJzdCBCb2FyCgImJUZpcnN0IEJvYXIgZnJvbSB0aGUgQm9hcnMgY29sbGVj" + +"dGlvbiEKAgYFQ2hyaXMKAiAfaHR0cHM6Ly9nZXQtYS1ib2FyLmZ1bGx1cmwuY29tLwACARIBAQIJ" + +"FAgGFQgEGQgEEAgEDwsDAQgEIAsDAQgEGAgCDQUTCAkCAgELAwAAAAACXw4AOAAEBAUICwEBBwAn" + +"CwAKATgBDAMOAwoBOAIMAg0CBwERAwcCEQMHAxEDBwQRAwcFEQMHBhEDBwcRAwcIEQMHCREDBwoR" + +"A0AMCgAAAAAAAAAHCxEDBwwRAwcNEQMHDhEDBw8RAwcQEQMHEREDBxIRAwcTEQMHFBEDQAwKAAAA" + +"AAAAADgDCwIKAS4RCjgECwMKAS4RCjgFCgERBgcVEQMHFhEDBxcRAwcYEQM4BjgHBgoAAAAAAAAA" + +"EgIKAS4RCgcZEQwSAQsBLhEKOAgCAA=="), + Lists.newArrayList( + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000002"), + null, + 30000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); ``` ### MoveCall ```java - CompletableFuture res = - sui.moveCall( - "", - "", - "", - "", - [], - [], - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); +TransactionBlockResponseOptions transactionBlockResponseOptions= + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + + io.sui.models.transactions.TypeTag.StructType structType= + new io.sui.models.transactions.TypeTag.StructType(); + io.sui.models.transactions.StructTag structTag=new StructTag(); + structTag.setAddress("0x02"); + structTag.setModule("sui"); + structTag.setName("SUI"); + structType.setStructTag(structTag); + CompletableFuture res= + sui.moveCall( + sender.get(), + "0x02", + "pay", + "split", + Lists.newArrayList(structType), + Lists.newArrayList(suiObjectResponse.getData().getObjectId(),10000L), + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); ``` -### BatchTransaction +### SponsoredTransaction ```java - CompletableFuture res = - sui.batchTransaction( - "", - [], - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); +CompletableFuture res= + sui.newTransactionBlock() + .thenCompose( + (Function>) + transactionBlock->{ + transactionBlock.setExpiration(null); + transactionBlock.setSender(sender.get()); + return transactionBlock + .transferObjects( + Lists.newArrayList(objects.get(0).getData().getObjectId()), + recipient.get()) + .thenCompose( + (Function>) + argument->{ + final CompletableFuture + transactionDataCompletableFuture= + transactionBlock + .setGasData( + Lists.newArrayList(), + sponsor.get(), + 3000000L, + null) + .thenCompose( + (Function< + Void, + CompletableFuture>) + unused->transactionBlock.build()); + + TransactionBlockResponseOptions + transactionBlockResponseOptions= + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + return transactionDataCompletableFuture.thenCompose( + (Function< + TransactionData, + CompletableFuture>) + transactionData->{ + Intent intent=sui.transactionDataIntent(); + String sponsorSig= + sui.signTransactionBlock( + sponsor.get(),transactionData,intent); + String senderSig= + sui.signTransactionBlock( + sender.get(),transactionData,intent); + return sui.executeTransaction( + transactionData, + Lists.newArrayList(senderSig,sponsorSig), + transactionBlockResponseOptions, + ExecuteTransactionRequestType + .WaitForLocalExecution); + }); + }); + }); ``` -For more examples, you can see [SuiIntTests](https://github.com/GrapeBaBa/sui4j/blob/main/src/integrationTest/java/io/sui/SuiIntTests.java) +For more examples, you can +see [SuiIntTests](https://github.com/GrapeBaBa/sui4j/blob/main/src/integrationTest/java/io/sui/SuiIntTests.java) diff --git a/docs/coin.md b/docs/coin.md index 250bd46..488d7b7 100644 --- a/docs/coin.md +++ b/docs/coin.md @@ -3,53 +3,49 @@ ### TransferSui ```java - CompletableFuture res = - sui.transferSui( - "", - "", - , - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); -``` - -### PaySui +TransactionBlockResponseOptions transactionBlockResponseOptions = +new TransactionBlockResponseOptions(); +transactionBlockResponseOptions.setShowEffects(true); +transactionBlockResponseOptions.setShowEvents(true); +transactionBlockResponseOptions.setShowInput(true); +transactionBlockResponseOptions.setShowObjectChanges(true); + +CompletableFuture res = + sui.transferSui( + sender.get(), + null, + recipient.get(), + 20000L, + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); -```java - CompletableFuture res = - sui.paySui( - "", - [""], - [""], - [], - , - ExecuteTransactionRequestType.WaitForLocalExecution); -``` - -### SplitCoin - -```java - CompletableFuture res = - sui.splitCoin( - "", - "", - [], - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); ``` ### MergeCoins ```java - CompletableFuture res = - sui.mergeCoins( - "", - "", - "", - "", - , - ExecuteTransactionRequestType.WaitForLocalExecution); +TransactionBlockResponseOptions transactionBlockResponseOptions = + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + +CompletableFuture res = + sui.mergeCoin( + sender.get(), + dest, + source, + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); ``` For more examples, you can see [SuiIntTests](https://github.com/GrapeBaBa/sui4j/blob/main/src/integrationTest/java/io/sui/SuiIntTests.java) diff --git a/docs/event.md b/docs/event.md index abaa5e4..2761ed5 100644 --- a/docs/event.md +++ b/docs/event.md @@ -3,16 +3,12 @@ ### SubscribeEvent ```java - EventTypeEventFilter eventFilter = new EventTypeEventFilter(); - eventFilter.setEventType(EventType.CoinBalanceChange); - Disposable disposable = - sui.subscribeEvent( - eventFilter, - , - ); - moveCall(); // transaction invocation - - disposable.dispose(); // undo subscribe + AllEventFilter eventFilter = new AllEventFilter(); + + Disposable disposable = + SUI.subscribeEvent(eventFilter, System.out::println, System.out::println); + + disposable.dispose(); ``` For more examples, you can see [SuiIntTests](https://github.com/GrapeBaBa/sui4j/blob/main/src/integrationTest/java/io/sui/SuiIntTests.java) diff --git a/docs/favicon16x16.png b/docs/favicon16x16.png deleted file mode 100644 index 42079f5..0000000 Binary files a/docs/favicon16x16.png and /dev/null differ diff --git a/docs/favicon192x192.png b/docs/favicon192x192.png deleted file mode 100644 index 945094e..0000000 Binary files a/docs/favicon192x192.png and /dev/null differ diff --git a/docs/favicon32x32.png b/docs/favicon32x32.png deleted file mode 100644 index c3b7b22..0000000 Binary files a/docs/favicon32x32.png and /dev/null differ diff --git a/docs/index.md b/docs/index.md index 08f5dcb..d9c4e17 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,14 +7,16 @@ Sui4j is a robust, reactive, type safe Java library for working with Smart Contr This allows you to work with the [@MystenLabs/sui](https://docs.sui.io/) blockchain, without the additional overhead of having to write your own integration code for the platform in JVM ecosystem. -The vision of sui4j is inspired by [Web3j](https://docs.web3j.io/), expect to accelerate JVM and Android ecosystem to integrate [@MystenLabs/sui](https://docs.sui.io/) network easily. +The vision of sui4j is inspired by [Web3j](https://docs.web3j.io/), expect to accelerate JVM and +Android ecosystem to integrate [@MystenLabs/sui](https://docs.sui.io/) network easily. Features ======== - Complete implementation of @MystenLabs/sui's [JSON-RPC](https://docs.sui.io/sui-jsonrpc) client API over HTTP -- [BCS](https://github.com/diem/bcs) serialisation/deserialization support +- [BCS](https://github.com/diem/bcs) serialisation/deserialization support in Java +- Sui Programmable Transaction support - Native reactive and asynchronous style API - Easy to use with utility class - Comprehensive integration tests and unit tests to guarantee high quality @@ -25,8 +27,7 @@ Core Dependencies - [RxJava](https://github.com/ReactiveX/RxJava) for its reactive-functional API - [OKHttp](https://square.github.io/okhttp/) for HTTP connections -- [Gson](https://github.com/google/gson) for fast JSON - serialisation/deserialization +- [Gson](https://github.com/google/gson) for fast JSON serialisation/deserialization - [Bouncy Castle](https://www.bouncycastle.org/) for crypto - [Guava](https://github.com/google/guava) for utility diff --git a/docs/initsui.md b/docs/initsui.md index c290a5f..0c392e3 100644 --- a/docs/initsui.md +++ b/docs/initsui.md @@ -1,16 +1,9 @@ ## Init sui client ```java - Sui sui = new Sui("", "") + Sui sui = new Sui("", "", "") ``` -or -```java - Sui sui = new Sui("", "", false) -``` - -To init sui client, you must provide the sui full node endpoint and keystore path. -The third parameter represents if enable local transaction builder. -By default, it is enabled since performance, however you still can use remote transaction builder by pass `false`. +To init sui client, you must provide the sui full node endpoint, faucet endpoint and keystore path. > **Note:** You only need **one** sui client instance in your application. \ No newline at end of file diff --git a/docs/quickstart.md b/docs/quickstart.md index a6ffa45..50f9dd1 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -7,7 +7,7 @@ me.grapebaba sui4j -0.4.2 +0.4.3 ``` @@ -15,42 +15,34 @@ ```groovy // https://mvnrepository.com/artifact/me.grapebaba/sui4j -implementation 'me.grapebaba:sui4j:0.4.2' +implementation 'me.grapebaba:sui4j:0.4.3' ``` ## Use Sui4j -### Mint an example NFT +### Transfer coin ```java - Sui sui = new Sui("", "", true); - CompletableFuture res = - sui.moveCall( - "0x0a7421363a1f6a82800f7c9340ac02b5905798cb", - "0x0000000000000000000000000000000000000002", - "devnet_nft", - "mint", - Lists.newArrayList(), - Lists.newArrayList( - "Example NFT", - "An example NFT.", - "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"), - null, - 2000L, - ExecuteTransactionRequestType.WaitForLocalExecution); -``` +Sui sui = new Sui("","",""); -### Transfer coin +TransactionBlockResponseOptions transactionBlockResponseOptions = +new TransactionBlockResponseOptions(); +transactionBlockResponseOptions.setShowEffects(true); +transactionBlockResponseOptions.setShowEvents(true); +transactionBlockResponseOptions.setShowInput(true); +transactionBlockResponseOptions.setShowObjectChanges(true); -```java - Sui sui = new Sui("", "", true); - CompletableFuture res = +CompletableFuture res = sui.transferSui( - "0x4a2a5a8e193b608a802cd733158ccb63c2092bdb", - "0x42f92e4c7ceec704941b48dd8919afa991913db8", - 2000L, - "0xa0fd2a6814cff90d4463fb7e5b5b81d01d763472", - 20000L, - ExecuteTransactionRequestType.WaitForLocalExecution); + "0x490174dbcac203f199d9dc50780f95c3a772a3c7357c5d98924885cd818f6980", + null, + "0x4543a8d956875317817c0c794c41c4b2e9a223faf2c1be0aa2c35e48acd8be42", + 20000L, + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); ``` \ No newline at end of file diff --git a/docs/sui4j.png b/docs/sui4j.png new file mode 100644 index 0000000..1775e82 Binary files /dev/null and b/docs/sui4j.png differ diff --git a/mkdocs.yml b/mkdocs.yml index b16cbc1..be5f0db 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -37,33 +37,33 @@ theme: # - toc.integrate palette: - scheme: default - primary: indigo - accent: indigo + primary: white + accent: white toggle: icon: material/brightness-7 name: Switch to dark mode - scheme: slate - primary: indigo - accent: indigo + primary: white + accent: white toggle: icon: material/brightness-4 name: Switch to light mode font: text: Roboto code: Roboto Mono - logo: SuiLogo.png - favicon: favicon16x16.png + logo: sui4j.png + favicon: sui4j.png nav: - Home: index.md - Quickstart: quickstart.md - Getting Started: - Init sui client: initsui.md + - New address: address.md - Coin transaction: coin.md - Object and Smart Contract: call.md - Subscribe Events: event.md - Build: build.md -# - Manual Configuration: getting_started/manual_configuration.md markdown_extensions: - abbr diff --git a/src/integrationTest/java/io/sui/EventClientImplIntTests.java b/src/integrationTest/java/io/sui/EventClientImplIntTests.java index 48832bd..191e93f 100644 --- a/src/integrationTest/java/io/sui/EventClientImplIntTests.java +++ b/src/integrationTest/java/io/sui/EventClientImplIntTests.java @@ -25,12 +25,11 @@ import io.sui.jsonrpc.JsonRpcClientProvider; import io.sui.jsonrpc.OkHttpJsonRpcClientProvider; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; import io.sui.models.events.EventFilter; import io.sui.models.events.EventFilter.AllEventFilter; -import io.sui.models.events.EventFilter.EventTypeEventFilter; -import io.sui.models.events.EventFilter.ModuleEventFilter; -import io.sui.models.events.EventType; +import io.sui.models.events.EventFilter.MoveModuleEventFilter; +import io.sui.models.events.SuiEvent; +import io.sui.models.objects.MoveModule; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -63,15 +62,15 @@ static void beforeAll() { void subscribeEvent() { EventFilter.PackageEventFilter packageEventFilter = new EventFilter.PackageEventFilter(); packageEventFilter.setSuiPackage("0x2"); - EventFilter.ModuleEventFilter moduleEventFilter = new ModuleEventFilter(); - moduleEventFilter.setModule("devnet_nft"); - EventFilter.EventTypeEventFilter eventTypeEventFilter = new EventTypeEventFilter(); - eventTypeEventFilter.setEventType(EventType.MoveEvent); + MoveModuleEventFilter moveModuleEventFilter = new MoveModuleEventFilter(); + MoveModule moveModule = new MoveModule(); + moveModule.setSuiPackage("0x2"); + moveModule.setModule("devnet_nft"); + moveModuleEventFilter.setModule(moveModule); EventFilter.AllEventFilter allEventFilter = new AllEventFilter(); allEventFilter.getAll().add(packageEventFilter); - allEventFilter.getAll().add(moduleEventFilter); - allEventFilter.getAll().add(eventTypeEventFilter); - Consumer onNext = System.out::println; + allEventFilter.getAll().add(moveModuleEventFilter); + Consumer onNext = System.out::println; Consumer onError = Throwable::printStackTrace; eventClient.subscribeEvent(allEventFilter, onNext, onError); diff --git a/src/integrationTest/java/io/sui/QueryClientImplIntTests.java b/src/integrationTest/java/io/sui/QueryClientImplIntTests.java index 91392cc..9348b43 100644 --- a/src/integrationTest/java/io/sui/QueryClientImplIntTests.java +++ b/src/integrationTest/java/io/sui/QueryClientImplIntTests.java @@ -106,7 +106,6 @@ void getObjectsOwnedByAddressIsNotEmpty() throws ExecutionException, Interrupted "0xb43d0468fbc80c81931b73a4b9ef4663e671b65a07ae5b336a0e7d8a70ac0646", query, null, - null, null); CompletableFuture future = new CompletableFuture<>(); res.whenComplete( @@ -132,7 +131,6 @@ void getObjectsOwnedByAddressIsNotEmpty() throws ExecutionException, Interrupted "0xb43d0468fbc80c81931b73a4b9ef4663e671b65a07ae5b336a0e7d8a70ac0646", query1, null, - null, null); CompletableFuture future1 = new CompletableFuture<>(); res1.whenComplete( diff --git a/src/integrationTest/java/io/sui/SuiIntTests.java b/src/integrationTest/java/io/sui/SuiIntTests.java index 81eb52c..e868fe8 100644 --- a/src/integrationTest/java/io/sui/SuiIntTests.java +++ b/src/integrationTest/java/io/sui/SuiIntTests.java @@ -16,37 +16,21 @@ package io.sui; -// -// import static org.junit.jupiter.api.Assertions.assertNotNull; -// -// import com.google.common.collect.Lists; -// import io.reactivex.rxjava3.disposables.Disposable; -// import io.reactivex.rxjava3.functions.Consumer; -// import io.sui.crypto.ED25519KeyPair; -// import io.sui.crypto.SECP256K1KeyPair; -// import io.sui.models.events.EventEnvelope; -// import io.sui.models.events.EventFilter.EventTypeEventFilter; -// import io.sui.models.events.EventType; -// import io.sui.models.objects.SuiObjectInfo; -// import io.sui.models.transactions.ExecuteTransactionRequestType; -// import io.sui.models.transactions.ExecuteTransactionResponse; -// import io.sui.models.transactions.RPCTransactionRequestParams; -// import io.sui.models.transactions.RPCTransactionRequestParams.MoveCallParams; -// import io.sui.models.transactions.RPCTransactionRequestParams.MoveCallRequestParams; -// import io.sui.models.transactions.RPCTransactionRequestParams.TransferObjectParams; -// import io.sui.models.transactions.RPCTransactionRequestParams.TransferObjectRequestParams; -// import java.util.ArrayList; -// import java.util.List; -// import java.util.Optional; -// import java.util.concurrent.CompletableFuture; - import com.google.common.collect.Lists; +import io.reactivex.rxjava3.disposables.Disposable; +import io.sui.bcsgen.Argument; +import io.sui.bcsgen.Intent; +import io.sui.bcsgen.TransactionData; +import io.sui.clients.TransactionBlock; import io.sui.crypto.KeyResponse; import io.sui.crypto.SignatureScheme; import io.sui.models.FaucetResponse; +import io.sui.models.events.EventFilter.AllEventFilter; +import io.sui.models.objects.Balance; import io.sui.models.objects.ObjectDataOptions; import io.sui.models.objects.ObjectResponseQuery; +import io.sui.models.objects.PaginatedCoins; import io.sui.models.objects.PaginatedObjectsResponse; import io.sui.models.objects.SuiObjectResponse; import io.sui.models.transactions.ExecuteTransactionRequestType; @@ -60,9 +44,10 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.stream.Collectors; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -74,60 +59,49 @@ */ public class SuiIntTests { - private static final String BASE_URL = "http://localhost:9000"; + // private static final String BASE_URL = "http://localhost:9000"; + private static final String BASE_NODE_URL = "https://fullnode.devnet.sui.io:443"; - private static final String BASE_FAUCET_URL = "http://localhost:9123"; - // private static final String BASE_FAUCET_URL = "https://faucet.testnet.sui.io"; + // private static final String BASE_FAUCET_URL = "http://localhost:9123"; + private static final String BASE_FAUCET_URL = "https://faucet.devnet.sui.io"; // private static final String TEST_KEY_STORE_PATH = // System.getProperty("user.home") + "/.sui/sui_config/sui.keystore"; - private static final String TEST_KEY_STORE_PATH = + private static final String KEY_STORE_PATH = Paths.get("src/integrationTest/sui.keystore").toAbsolutePath().toString(); - private static Sui sui; - - /** Before all. */ - @BeforeAll - static void beforeAll() { - sui = new Sui(BASE_URL, BASE_FAUCET_URL, TEST_KEY_STORE_PATH, true); - } + private static final Sui SUI = new Sui(BASE_NODE_URL, BASE_FAUCET_URL, KEY_STORE_PATH); /** New address. */ @Test @DisplayName("Test newAddress.") void newAddress() { - KeyResponse res1 = sui.newAddress(SignatureScheme.ED25519); + KeyResponse res1 = SUI.newAddress(SignatureScheme.ED25519); System.out.printf("mnemonic+address:%s%n", res1); System.out.println(); - KeyResponse res2 = sui.newAddress(SignatureScheme.ED25519); + KeyResponse res2 = SUI.newAddress(SignatureScheme.ED25519); System.out.printf("mnemonic+address:%s%n", res2); System.out.println(); - KeyResponse res3 = sui.newAddress(SignatureScheme.ED25519); + KeyResponse res3 = SUI.newAddress(SignatureScheme.Secp256k1); System.out.printf("mnemonic+address:%s%n", res3); System.out.println(); - - KeyResponse res4 = sui.newAddress(SignatureScheme.Secp256k1); - System.out.printf("mnemonic+address:%s%n", res4); - System.out.println(); - - KeyResponse res5 = sui.newAddress(SignatureScheme.Secp256k1); - System.out.printf("mnemonic+address:%s%n", res5); - System.out.println(); } /** Request sui from faucet. */ @Test @DisplayName("Test requestSuiFromFaucet.") void requestSuiFromFaucet() { - sui.addresses() + SUI.addresses() .forEach( s -> { System.out.printf("address:%s%n", s); - CompletableFuture res = sui.requestSuiFromFaucet(s); + CompletableFuture res = SUI.requestSuiFromFaucet(s); + try { + TimeUnit.SECONDS.sleep(2); System.out.printf("faucet response: %s%n%n", res.get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -136,107 +110,6 @@ void requestSuiFromFaucet() { }); } - /** - * Gets objects owned by address. - * - * @throws ExecutionException the execution exception - * @throws InterruptedException the interrupted exception - */ - @Test - @DisplayName("Test getObjectsOwnedByAddress.") - void getObjectsOwnedByAddress() throws ExecutionException, InterruptedException { - final Optional sender = - sui.addresses().stream() - .filter( - s -> { - try { - return sui.getObjectsOwnedByAddress( - s, new ObjectResponseQuery(), null, null, null) - .get() - .getData() - .size() - > 1; - } catch (InterruptedException | ExecutionException e) { - return false; - } - }) - .findFirst(); - if (!sender.isPresent()) { - Assertions.fail(); - } - CompletableFuture res = - sui.getObjectsOwnedByAddress(sender.get(), new ObjectResponseQuery(), null, null, null); - System.out.printf("paginated objects:%s%n", res.get()); - } - - /** - * Transfer sui. - * - * @throws ExecutionException the execution exception - * @throws InterruptedException the interrupted exception - */ - @SuppressWarnings("checkstyle:CommentsIndentation") - @Test - @DisplayName("Test transferSui.") - void transferSui() throws ExecutionException, InterruptedException { - ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); - objectResponseQuery.setOptions(new ObjectDataOptions()); - final Optional sender = - sui.addresses().stream() - .filter( - s -> { - try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) - .get() - .getData() - .size() - > 1; - } catch (InterruptedException | ExecutionException e) { - return false; - } - }) - .findFirst(); - if (!sender.isPresent()) { - Assertions.fail(); - } - - final Optional recipient = - sui.addresses().stream().filter(s -> !s.equals(sender.get())).findFirst(); - if (!recipient.isPresent()) { - Assertions.fail(); - } - - TransactionBlockResponseOptions transactionBlockResponseOptions = - new TransactionBlockResponseOptions(); - transactionBlockResponseOptions.setShowEffects(true); - transactionBlockResponseOptions.setShowEvents(true); - transactionBlockResponseOptions.setShowInput(true); - transactionBlockResponseOptions.setShowObjectChanges(true); - CompletableFuture res2 = - sui.transferSui( - sender.get(), - null, - recipient.get(), - 2000L, - null, - 5000L, - null, - null, - transactionBlockResponseOptions, - ExecuteTransactionRequestType.WaitForLocalExecution); - CompletableFuture future = new CompletableFuture<>(); - res2.whenComplete( - (transactionResponse, throwable) -> { - if (throwable != null) { - future.complete(throwable); - } else { - future.complete(transactionResponse); - } - }); - - System.out.println(future.get()); - } - /** * Move call. * @@ -248,11 +121,11 @@ void transferSui() throws ExecutionException, InterruptedException { void moveCall() throws ExecutionException, InterruptedException { ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); final Optional sender = - sui.addresses().stream() + SUI.addresses().stream() .filter( s -> { try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) .get() .getData() .size() @@ -266,7 +139,7 @@ void moveCall() throws ExecutionException, InterruptedException { Assertions.fail(); } final SuiObjectResponse suiObjectResponse = - sui.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null, null) + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null) .get() .getData() .get(0); @@ -285,7 +158,7 @@ void moveCall() throws ExecutionException, InterruptedException { structTag.setName("SUI"); structType.setStructTag(structTag); CompletableFuture res = - sui.moveCall( + SUI.moveCall( sender.get(), "0x02", "pay", @@ -293,94 +166,13 @@ void moveCall() throws ExecutionException, InterruptedException { Lists.newArrayList(structType), Lists.newArrayList(suiObjectResponse.getData().getObjectId(), 10000L), null, - 10000L, + 3000000L, null, null, transactionBlockResponseOptions, ExecuteTransactionRequestType.WaitForLocalExecution); - CompletableFuture future = new CompletableFuture<>(); - res.whenComplete( - (transactionResponse, throwable) -> { - if (throwable != null) { - future.complete(throwable); - } else { - future.complete(transactionResponse); - } - }); - - System.out.println(future.get()); - } - /** - * Merge coin. - * - * @throws ExecutionException the execution exception - * @throws InterruptedException the interrupted exception - */ - @Test - @DisplayName("Test mergeCoin.") - void mergeCoin() throws ExecutionException, InterruptedException { - ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); - final Optional sender = - sui.addresses().stream() - .filter( - s -> { - try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) - .get() - .getData() - .size() - > 3; - } catch (InterruptedException | ExecutionException e) { - return false; - } - }) - .findFirst(); - if (!sender.isPresent()) { - Assertions.fail(); - } - - TransactionBlockResponseOptions transactionBlockResponseOptions = - new TransactionBlockResponseOptions(); - transactionBlockResponseOptions.setShowEffects(true); - transactionBlockResponseOptions.setShowEvents(true); - transactionBlockResponseOptions.setShowInput(true); - transactionBlockResponseOptions.setShowObjectChanges(true); - - String dest = - sui.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null, null) - .get() - .getData() - .get(0) - .getData() - .getObjectId(); - List source = - sui.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null, null).get() - .getData().subList(1, 2).stream() - .map(suiObjectResponse -> suiObjectResponse.getData().getObjectId()) - .collect(Collectors.toList()); - CompletableFuture res = - sui.mergeCoin( - sender.get(), - dest, - source, - null, - 5000L, - null, - null, - transactionBlockResponseOptions, - ExecuteTransactionRequestType.WaitForLocalExecution); - CompletableFuture future = new CompletableFuture<>(); - res.whenComplete( - (transactionResponse, throwable) -> { - if (throwable != null) { - future.complete(throwable); - } else { - future.complete(transactionResponse); - } - }); - - System.out.println(future.get()); + System.out.println(res.get()); } /** @@ -395,11 +187,11 @@ void transferObjects() throws ExecutionException, InterruptedException { ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); objectResponseQuery.setOptions(new ObjectDataOptions()); final Optional sender = - sui.addresses().stream() + SUI.addresses().stream() .filter( s -> { try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) .get() .getData() .size() @@ -411,11 +203,11 @@ void transferObjects() throws ExecutionException, InterruptedException { .findFirst(); if (sender.isPresent()) { - final Optional receipt = - sui.addresses().stream().filter(s -> !s.equals(sender.get())).findFirst(); - if (receipt.isPresent()) { + final Optional recipient = + SUI.addresses().stream().filter(s -> !s.equals(sender.get())).findFirst(); + if (recipient.isPresent()) { List objects = - sui.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null, null) + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null) .get() .getData(); TransactionBlockResponseOptions transactionBlockResponseOptions = @@ -425,12 +217,12 @@ void transferObjects() throws ExecutionException, InterruptedException { transactionBlockResponseOptions.setShowInput(true); transactionBlockResponseOptions.setShowObjectChanges(true); CompletableFuture res = - sui.transferObjects( + SUI.transferObjects( sender.get(), Lists.newArrayList(objects.get(0).getData().getObjectId()), - receipt.get(), + recipient.get(), null, - 3000L, + 3000000L, null, null, transactionBlockResponseOptions, @@ -466,11 +258,11 @@ void publish() throws ExecutionException, InterruptedException { ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); objectResponseQuery.setOptions(new ObjectDataOptions()); final Optional sender = - sui.addresses().stream() + SUI.addresses().stream() .filter( s -> { try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) .get() .getData() .size() @@ -489,8 +281,8 @@ void publish() throws ExecutionException, InterruptedException { transactionBlockResponseOptions.setShowEvents(true); transactionBlockResponseOptions.setShowInput(true); transactionBlockResponseOptions.setShowObjectChanges(true); - CompletableFuture res1 = - sui.publish( + CompletableFuture res = + SUI.publish( sender.get(), Lists.newArrayList( "oRzrCwYAAAAKAQAUAhQsA0BJBIkBEgWbAWcHggLNAgjPBGAGrwXCAwrxCC0MngnUAQAMAR4B" @@ -523,22 +315,303 @@ void publish() throws ExecutionException, InterruptedException { "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000002"), null, - 10000L, + 30000000L, null, null, transactionBlockResponseOptions, ExecuteTransactionRequestType.WaitForLocalExecution); - CompletableFuture future = new CompletableFuture<>(); - res1.whenComplete( - (transactionResponse, throwable) -> { - if (throwable != null) { - future.complete(throwable); - } else { - future.complete(transactionResponse); - } - }); - - System.out.println(future.get()); + + System.out.println(res.get()); + } + + @Test + @DisplayName("Test subscribeEvent.") + void subscribeEvent() throws InterruptedException { + AllEventFilter eventFilter = new AllEventFilter(); + + Disposable disposable = + SUI.subscribeEvent(eventFilter, System.out::println, System.out::println); + + TimeUnit.SECONDS.sleep(10); + + disposable.dispose(); + } + + @Test + @DisplayName("Test sponsoredTransaction.") + void sponsoredTransaction() throws ExecutionException, InterruptedException { + ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); + objectResponseQuery.setOptions(new ObjectDataOptions()); + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) + .get() + .getData() + .size() + > 1; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + + final Optional recipient = + SUI.addresses().stream().filter(s -> !s.equals(sender.get())).findFirst(); + if (!recipient.isPresent()) { + Assertions.fail(); + } + + final Optional sponsor = + SUI.addresses().stream() + .filter(s -> !s.equals(sender.get()) && !s.equals(recipient.get())) + .findFirst(); + if (!sponsor.isPresent()) { + Assertions.fail(); + } + + List objects = + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null).get().getData(); + + CompletableFuture res = + SUI.newTransactionBlock() + .thenCompose( + (Function>) + transactionBlock -> { + transactionBlock.setExpiration(null); + transactionBlock.setSender(sender.get()); + return transactionBlock + .transferObjects( + Lists.newArrayList(objects.get(0).getData().getObjectId()), + recipient.get()) + .thenCompose( + (Function>) + argument -> { + final CompletableFuture + transactionDataCompletableFuture = + transactionBlock + .setGasData( + Lists.newArrayList(), + sponsor.get(), + 3000000L, + null) + .thenCompose( + (Function< + Void, + CompletableFuture>) + unused -> transactionBlock.build()); + + TransactionBlockResponseOptions + transactionBlockResponseOptions = + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + return transactionDataCompletableFuture.thenCompose( + (Function< + TransactionData, + CompletableFuture>) + transactionData -> { + Intent intent = SUI.transactionDataIntent(); + String sponsorSig = + SUI.signTransactionBlock( + sponsor.get(), transactionData, intent); + String senderSig = + SUI.signTransactionBlock( + sender.get(), transactionData, intent); + return SUI.executeTransaction( + transactionData, + Lists.newArrayList(senderSig, sponsorSig), + transactionBlockResponseOptions, + ExecuteTransactionRequestType + .WaitForLocalExecution); + }); + }); + }); + + System.out.println(res.get()); + } + + @Test + @DisplayName("Test getAllCoins.") + void getAllCoins() throws ExecutionException, InterruptedException { + ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); + objectResponseQuery.setOptions(new ObjectDataOptions()); + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) + .get() + .getData() + .size() + > 1; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + CompletableFuture res = SUI.getAllCoins(sender.get(), null, null); + System.out.printf("paginated coins:%s%n", res.get()); + } + + @Test + @DisplayName("Test getBalance.") + void getBalance() throws ExecutionException, InterruptedException { + ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); + objectResponseQuery.setOptions(new ObjectDataOptions()); + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) + .get() + .getData() + .size() + > 1; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + CompletableFuture res = SUI.getBalance(sender.get(), null); + System.out.printf("balance:%s%n", res.get()); + } + + /** + * Transfer sui. + * + * @throws ExecutionException the execution exception + * @throws InterruptedException the interrupted exception + */ + @SuppressWarnings("checkstyle:CommentsIndentation") + @Test + @DisplayName("Test transferSui.") + void transferSui() throws ExecutionException, InterruptedException { + ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); + objectResponseQuery.setOptions(new ObjectDataOptions()); + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) + .get() + .getData() + .size() + > 1; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + + final Optional recipient = + SUI.addresses().stream().filter(s -> !s.equals(sender.get())).findFirst(); + if (!recipient.isPresent()) { + Assertions.fail(); + } + + TransactionBlockResponseOptions transactionBlockResponseOptions = + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + CompletableFuture res = + SUI.transferSui( + sender.get(), + null, + recipient.get(), + 20000L, + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); + + System.out.println(res.get()); + } + + /** + * Merge coin. + * + * @throws ExecutionException the execution exception + * @throws InterruptedException the interrupted exception + */ + @Test + @DisplayName("Test mergeCoin.") + void mergeCoin() throws ExecutionException, InterruptedException { + ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) + .get() + .getData() + .size() + > 3; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + + TransactionBlockResponseOptions transactionBlockResponseOptions = + new TransactionBlockResponseOptions(); + transactionBlockResponseOptions.setShowEffects(true); + transactionBlockResponseOptions.setShowEvents(true); + transactionBlockResponseOptions.setShowInput(true); + transactionBlockResponseOptions.setShowObjectChanges(true); + + String dest = + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null) + .get() + .getData() + .get(0) + .getData() + .getObjectId(); + List source = + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null).get().getData() + .subList(1, 2).stream() + .map(suiObjectResponse -> suiObjectResponse.getData().getObjectId()) + .collect(Collectors.toList()); + CompletableFuture res = + SUI.mergeCoin( + sender.get(), + dest, + source, + null, + 3000000L, + null, + null, + transactionBlockResponseOptions, + ExecuteTransactionRequestType.WaitForLocalExecution); + + System.out.println(res.get()); } /** @@ -550,10 +623,43 @@ void publish() throws ExecutionException, InterruptedException { @Test @DisplayName("Test getTotalTransactionBlocks.") void getTotalTransactionBlocks() throws ExecutionException, InterruptedException { - CompletableFuture res = sui.getTotalTransactionBlocks(); + CompletableFuture res = SUI.getTotalTransactionBlocks(); System.out.printf("total transaction blocks:%d%n", res.get()); } + /** + * Gets objects owned by address. + * + * @throws ExecutionException the execution exception + * @throws InterruptedException the interrupted exception + */ + @Test + @DisplayName("Test getObjectsOwnedByAddress.") + void getObjectsOwnedByAddress() throws ExecutionException, InterruptedException { + final Optional sender = + SUI.addresses().stream() + .filter( + s -> { + try { + return SUI.getObjectsOwnedByAddress(s, new ObjectResponseQuery(), null, null) + .get() + .getData() + .size() + > 1; + } catch (InterruptedException | ExecutionException e) { + return false; + } + }) + .findFirst(); + if (!sender.isPresent()) { + Assertions.fail(); + } + System.out.println(sender.get()); + CompletableFuture res = + SUI.getObjectsOwnedByAddress(sender.get(), null, null, null); + System.out.printf("paginated objects:%s%n", res.get()); + } + /** * Query transaction blocks. * @@ -565,7 +671,7 @@ void getTotalTransactionBlocks() throws ExecutionException, InterruptedException void queryTransactionBlocks() throws ExecutionException, InterruptedException { TransactionBlockResponseQuery query = new TransactionBlockResponseQuery(); CompletableFuture res = - sui.queryTransactionBlocks(query, null, 10, false); + SUI.queryTransactionBlocks(query, null, 10, false); System.out.printf("paginated transaction blocks:%s%n", res.get()); } @@ -581,13 +687,13 @@ void queryTransactionBlocks() throws ExecutionException, InterruptedException { void getTransactionBlock() throws ExecutionException, InterruptedException { TransactionBlockResponseQuery query = new TransactionBlockResponseQuery(); CompletableFuture res = - sui.queryTransactionBlocks(query, null, 10, false); + SUI.queryTransactionBlocks(query, null, 10, false); TransactionBlockResponseOptions options = new TransactionBlockResponseOptions(); options.setShowInput(true); options.setShowEffects(true); CompletableFuture res1 = - sui.getTransactionBlock(res.get().getData().get(2).getDigest(), options); + SUI.getTransactionBlock(res.get().getData().get(2).getDigest(), options); System.out.printf("transaction block:%s%n", res1.get()); } @@ -602,13 +708,13 @@ void getTransactionBlock() throws ExecutionException, InterruptedException { void multiGetTransactionBlocks() throws ExecutionException, InterruptedException { TransactionBlockResponseQuery query = new TransactionBlockResponseQuery(); CompletableFuture res = - sui.queryTransactionBlocks(query, null, 10, false); + SUI.queryTransactionBlocks(query, null, 10, false); TransactionBlockResponseOptions options = new TransactionBlockResponseOptions(); options.setShowInput(true); options.setShowEffects(true); CompletableFuture> res1 = - sui.multiGetTransactionBlocks( + SUI.multiGetTransactionBlocks( Lists.newArrayList( res.get().getData().get(0).getDigest(), res.get().getData().get(1).getDigest()), options); @@ -627,11 +733,11 @@ void multiGetObjects() throws ExecutionException, InterruptedException { ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); objectResponseQuery.setOptions(new ObjectDataOptions()); final Optional sender = - sui.addresses().stream() + SUI.addresses().stream() .filter( s -> { try { - return sui.getObjectsOwnedByAddress(s, objectResponseQuery, null, null, null) + return SUI.getObjectsOwnedByAddress(s, objectResponseQuery, null, null) .get() .getData() .size() @@ -645,27 +751,12 @@ void multiGetObjects() throws ExecutionException, InterruptedException { Assertions.fail(); } List objects = - sui.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null, null).get() - .getData().stream() + SUI.getObjectsOwnedByAddress(sender.get(), objectResponseQuery, null, null).get().getData() + .stream() .map(suiObjectResponse -> suiObjectResponse.getData().getObjectId()) .collect(Collectors.toList()); CompletableFuture> res1 = - sui.multiGetObjects(objects, new ObjectDataOptions()); + SUI.multiGetObjects(objects, new ObjectDataOptions()); System.out.printf("object responses:%s%n", res1.get()); } - - // @Test - // @DisplayName("Test subscribeEvent.") - // void subscribeEvent() throws ExecutionException, InterruptedException { - // EventTypeEventFilter eventFilter = new EventTypeEventFilter(); - // eventFilter.setEventType(EventType.CoinBalanceChange); - // Disposable disposable = - // sui.subscribeEvent( - // eventFilter, - // System.out::println, - // System.out::println); - // moveCall(); - // - // disposable.dispose(); - // } } diff --git a/src/main/java/io/sui/Sui.java b/src/main/java/io/sui/Sui.java index 8c51365..186d982 100644 --- a/src/main/java/io/sui/Sui.java +++ b/src/main/java/io/sui/Sui.java @@ -32,13 +32,10 @@ import io.sui.clients.ExecutionClient; import io.sui.clients.ExecutionClientImpl; import io.sui.clients.FaucetClient; -import io.sui.clients.JsonRpcTransactionBuilder; -import io.sui.clients.LocalTransactionBuilder; import io.sui.clients.OkhttpFaucetClient; import io.sui.clients.QueryClient; import io.sui.clients.QueryClientImpl; import io.sui.clients.TransactionBlock; -import io.sui.clients.TransactionBuilder; import io.sui.crypto.FileBasedKeyStore; import io.sui.crypto.KeyResponse; import io.sui.crypto.KeyStore; @@ -51,11 +48,11 @@ import io.sui.jsonrpc.OkHttpJsonRpcClientProvider; import io.sui.models.FaucetResponse; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; import io.sui.models.events.EventFilter; import io.sui.models.events.EventId; import io.sui.models.events.EventQuery; import io.sui.models.events.PaginatedEvents; +import io.sui.models.events.SuiEvent; import io.sui.models.objects.Balance; import io.sui.models.objects.CheckpointContents; import io.sui.models.objects.CheckpointSummary; @@ -79,7 +76,6 @@ import io.sui.models.transactions.TransactionBlockResponse; import io.sui.models.transactions.TransactionBlockResponseOptions; import io.sui.models.transactions.TransactionBlockResponseQuery; -import io.sui.models.transactions.TransactionBytes; import io.sui.models.transactions.TransactionEffects; import io.sui.models.transactions.TypeTag; import java.util.List; @@ -103,8 +99,6 @@ public class Sui { private final QueryClient queryClient; - private final TransactionBuilder transactionBuilder; - private final ExecutionClient executionClient; private final EventClient eventClient; @@ -119,31 +113,11 @@ public class Sui { * @param keyStorePath the key store path */ public Sui(String fullNodeEndpoint, String faucetEndpoint, String keyStorePath) { - this(fullNodeEndpoint, faucetEndpoint, keyStorePath, true); - } - - /** - * Instantiates a new Sui. - * - * @param fullNodeEndpoint the full node endpoint - * @param faucetEndpoint the faucet endpoint - * @param keyStorePath the key store path - * @param useLocalTransactionBuilder the use local transaction builder - */ - public Sui( - String fullNodeEndpoint, - String faucetEndpoint, - String keyStorePath, - boolean useLocalTransactionBuilder) { this.keyStore = new FileBasedKeyStore(keyStorePath); final JsonHandler jsonHandler = new GsonJsonHandler(); final JsonRpcClientProvider jsonRpcClientProvider = new OkHttpJsonRpcClientProvider(fullNodeEndpoint, jsonHandler); this.queryClient = new QueryClientImpl(jsonRpcClientProvider); - this.transactionBuilder = - useLocalTransactionBuilder - ? new LocalTransactionBuilder(this.queryClient) - : new JsonRpcTransactionBuilder(jsonRpcClientProvider); this.executionClient = new ExecutionClientImpl(jsonRpcClientProvider); this.eventClient = new EventClientImpl(jsonRpcClientProvider); this.faucetClient = new OkhttpFaucetClient(faucetEndpoint, jsonHandler); @@ -503,7 +477,7 @@ public CompletableFuture publish( * @return the disposable */ public Disposable subscribeEvent( - EventFilter eventFilter, Consumer onNext, Consumer onError) { + EventFilter eventFilter, Consumer onNext, Consumer onError) { return this.eventClient.subscribeEvent(eventFilter, onNext, onError); } @@ -526,16 +500,11 @@ public CompletableFuture getObject( * @param query the query * @param cursor the cursor * @param limit the limit - * @param checkpointId the checkpoint id * @return the objects owned by address */ public CompletableFuture getObjectsOwnedByAddress( - String address, - ObjectResponseQuery query, - String cursor, - Integer limit, - String checkpointId) { - return queryClient.getObjectsOwnedByAddress(address, query, cursor, limit, checkpointId); + String address, ObjectResponseQuery query, String cursor, Integer limit) { + return queryClient.getObjectsOwnedByAddress(address, query, cursor, limit); } /** @@ -559,16 +528,52 @@ public CompletableFuture getTransactionBlock( return queryClient.getTransactionBlock(digest, options); } + /** + * Query transaction blocks completable future. + * + * @param query the query + * @param cursor the cursor + * @param limit the limit + * @param isDescOrder the is desc order + * @return the completable future + */ public CompletableFuture queryTransactionBlocks( TransactionBlockResponseQuery query, String cursor, Integer limit, boolean isDescOrder) { return queryClient.queryTransactionBlocks(query, cursor, limit, isDescOrder); } + /** + * Query objects completable future. + * + * @param query the query + * @param cursor the cursor + * @param limit the limit + * @return the completable future + */ + public CompletableFuture queryObjects( + ObjectResponseQuery query, String cursor, Integer limit) { + return queryClient.queryObjects(query, cursor, limit); + } + + /** + * Multi get transaction blocks completable future. + * + * @param digests the digests + * @param options the options + * @return the completable future + */ public CompletableFuture> multiGetTransactionBlocks( List digests, TransactionBlockResponseOptions options) { return queryClient.multiGetTransactionBlocks(digests, options); } + /** + * Multi get objects completable future. + * + * @param objectIds the object ids + * @param options the options + * @return the completable future + */ public CompletableFuture> multiGetObjects( List objectIds, ObjectDataOptions options) { return queryClient.multiGetObjects(objectIds, options); @@ -752,7 +757,8 @@ public CompletableFuture> getAllBalances(String address) { * @param limit the limit * @return the completable future */ - public CompletableFuture getAllCoins(String address, String cursor, long limit) { + public CompletableFuture getAllCoins( + String address, String cursor, Integer limit) { return queryClient.getAllCoins(address, cursor, limit); } @@ -852,15 +858,6 @@ public NavigableSet addresses() { return keyStore.addresses(); } - /** - * Gets transaction builder. - * - * @return the transaction builder - */ - public TransactionBuilder getTransactionBuilder() { - return transactionBuilder; - } - /** * Execute transaction completable future. * @@ -883,6 +880,31 @@ public CompletableFuture executeTransaction( requestType); } + /** + * Execute transaction completable future. + * + * @param transactionData the transaction data + * @param signatures the signatures + * @param transactionBlockResponseOptions the transaction block response options + * @param requestType the request type + * @return the completable future + */ + public CompletableFuture executeTransaction( + TransactionData transactionData, + List signatures, + TransactionBlockResponseOptions transactionBlockResponseOptions, + ExecuteTransactionRequestType requestType) { + try { + return executionClient.executeTransaction( + Base64.toBase64String(transactionData.bcsSerialize()), + signatures, + transactionBlockResponseOptions, + requestType); + } catch (SerializationError e) { + throw new BcsSerializationException(e); + } + } + /** * Execute transaction completable future. * @@ -924,6 +946,40 @@ public CompletableFuture executeTransaction( signatureScheme); } + /** + * Sign transaction block string. + * + * @param signer the signer + * @param transactionData the transaction data + * @param intent the intent + * @return the string + * @throws SigningException the signing exception + */ + public String signTransactionBlock(String signer, TransactionData transactionData, Intent intent) + throws SigningException { + final SuiKeyPair suiKeyPair = keyStore.getByAddress(signer); + final byte[] publicKey = suiKeyPair.publicKeyBytes(); + final SignatureScheme signatureScheme = suiKeyPair.signatureScheme(); + + final byte[] txBytes; + final byte[] intentBytes; + try { + txBytes = transactionData.bcsSerialize(); + intentBytes = intent.bcsSerialize(); + + final byte[] signature; + final Blake2b256 blake2b256 = new Blake2b256(); + final byte[] hash = blake2b256.digest(Arrays.concatenate(intentBytes, txBytes)); + signature = suiKeyPair.sign(hash); + + final byte[] serializedSignatureBytes = + Arrays.concatenate(new byte[] {signatureScheme.getScheme()}, signature, publicKey); + return Base64.toBase64String(serializedSignatureBytes); + } catch (SerializationError e) { + throw new BcsSerializationException(e); + } + } + private CompletableFuture signAndExecuteTransaction( byte[] transactionData, byte[] intentBytes, @@ -934,13 +990,9 @@ private CompletableFuture signAndExecuteTransaction( SignatureScheme signatureScheme) { final byte[] signature; try { - if ("0.28.0".equals(System.getenv("SUI_VERSION"))) { - signature = suiKeyPair.sign(Arrays.concatenate(intentBytes, transactionData)); - } else { - final Blake2b256 blake2b256 = new Blake2b256(); - final byte[] hash = blake2b256.digest(Arrays.concatenate(intentBytes, transactionData)); - signature = suiKeyPair.sign(hash); - } + final Blake2b256 blake2b256 = new Blake2b256(); + final byte[] hash = blake2b256.digest(Arrays.concatenate(intentBytes, transactionData)); + signature = suiKeyPair.sign(hash); } catch (SigningException e) { CompletableFuture future = new CompletableFuture<>(); @@ -959,44 +1011,12 @@ private CompletableFuture signAndExecuteTransaction( requestType); } - private Function> - signAndExecuteTransactionFunction( - String signer, - Intent intent, - TransactionBlockResponseOptions transactionBlockResponseOptions, - ExecuteTransactionRequestType requestType) { - return transactionBytes -> { - final SuiKeyPair suiKeyPair = keyStore.getByAddress(signer); - final byte[] publicKey = suiKeyPair.publicKeyBytes(); - final SignatureScheme signatureScheme = suiKeyPair.signatureScheme(); - final TransactionData transactionData = transactionBytes.getLocalTxBytes(); - - final byte[] txBytes; - final byte[] intentBytes; - try { - txBytes = - null != transactionData - ? transactionData.bcsSerialize() - : Base64.decode(transactionBytes.getTxBytes()); - intentBytes = intent.bcsSerialize(); - } catch (SerializationError e) { - CompletableFuture future = new CompletableFuture<>(); - future.completeExceptionally(new SuiApiException(new BcsSerializationException(e))); - return future; - } - - return signAndExecuteTransaction( - txBytes, - intentBytes, - transactionBlockResponseOptions, - requestType, - suiKeyPair, - publicKey, - signatureScheme); - }; - } - - private Intent transactionDataIntent() { + /** + * Transaction data intent intent. + * + * @return the intent + */ + public Intent transactionDataIntent() { final Intent.Builder intentBuilder = new Intent.Builder(); intentBuilder.app_id = 0; intentBuilder.scope = 0; diff --git a/src/main/java/io/sui/bcsgen/ChangeEpoch.java b/src/main/java/io/sui/bcsgen/ChangeEpoch.java index d885335..edaa1ad 100644 --- a/src/main/java/io/sui/bcsgen/ChangeEpoch.java +++ b/src/main/java/io/sui/bcsgen/ChangeEpoch.java @@ -7,15 +7,17 @@ public final class ChangeEpoch { public final @com.novi.serde.Unsigned Long storage_charge; public final @com.novi.serde.Unsigned Long computation_charge; public final @com.novi.serde.Unsigned Long storage_rebate; + public final @com.novi.serde.Unsigned Long non_refundable_storage_fee; public final @com.novi.serde.Unsigned Long epoch_start_timestamp_ms; public final java.util.List>, java.util.List>> system_packages; - public ChangeEpoch(@com.novi.serde.Unsigned Long epoch, ProtocolVersion protocol_version, @com.novi.serde.Unsigned Long storage_charge, @com.novi.serde.Unsigned Long computation_charge, @com.novi.serde.Unsigned Long storage_rebate, @com.novi.serde.Unsigned Long epoch_start_timestamp_ms, java.util.List>, java.util.List>> system_packages) { + public ChangeEpoch(@com.novi.serde.Unsigned Long epoch, ProtocolVersion protocol_version, @com.novi.serde.Unsigned Long storage_charge, @com.novi.serde.Unsigned Long computation_charge, @com.novi.serde.Unsigned Long storage_rebate, @com.novi.serde.Unsigned Long non_refundable_storage_fee, @com.novi.serde.Unsigned Long epoch_start_timestamp_ms, java.util.List>, java.util.List>> system_packages) { java.util.Objects.requireNonNull(epoch, "epoch must not be null"); java.util.Objects.requireNonNull(protocol_version, "protocol_version must not be null"); java.util.Objects.requireNonNull(storage_charge, "storage_charge must not be null"); java.util.Objects.requireNonNull(computation_charge, "computation_charge must not be null"); java.util.Objects.requireNonNull(storage_rebate, "storage_rebate must not be null"); + java.util.Objects.requireNonNull(non_refundable_storage_fee, "non_refundable_storage_fee must not be null"); java.util.Objects.requireNonNull(epoch_start_timestamp_ms, "epoch_start_timestamp_ms must not be null"); java.util.Objects.requireNonNull(system_packages, "system_packages must not be null"); this.epoch = epoch; @@ -23,6 +25,7 @@ public ChangeEpoch(@com.novi.serde.Unsigned Long epoch, ProtocolVersion protocol this.storage_charge = storage_charge; this.computation_charge = computation_charge; this.storage_rebate = storage_rebate; + this.non_refundable_storage_fee = non_refundable_storage_fee; this.epoch_start_timestamp_ms = epoch_start_timestamp_ms; this.system_packages = system_packages; } @@ -34,6 +37,7 @@ public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serd serializer.serialize_u64(storage_charge); serializer.serialize_u64(computation_charge); serializer.serialize_u64(storage_rebate); + serializer.serialize_u64(non_refundable_storage_fee); serializer.serialize_u64(epoch_start_timestamp_ms); TraitHelpers.serialize_vector_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(system_packages, serializer); serializer.decrease_container_depth(); @@ -53,6 +57,7 @@ public static ChangeEpoch deserialize(com.novi.serde.Deserializer deserializer) builder.storage_charge = deserializer.deserialize_u64(); builder.computation_charge = deserializer.deserialize_u64(); builder.storage_rebate = deserializer.deserialize_u64(); + builder.non_refundable_storage_fee = deserializer.deserialize_u64(); builder.epoch_start_timestamp_ms = deserializer.deserialize_u64(); builder.system_packages = TraitHelpers.deserialize_vector_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(deserializer); deserializer.decrease_container_depth(); @@ -81,6 +86,7 @@ public boolean equals(Object obj) { if (!java.util.Objects.equals(this.storage_charge, other.storage_charge)) { return false; } if (!java.util.Objects.equals(this.computation_charge, other.computation_charge)) { return false; } if (!java.util.Objects.equals(this.storage_rebate, other.storage_rebate)) { return false; } + if (!java.util.Objects.equals(this.non_refundable_storage_fee, other.non_refundable_storage_fee)) { return false; } if (!java.util.Objects.equals(this.epoch_start_timestamp_ms, other.epoch_start_timestamp_ms)) { return false; } if (!java.util.Objects.equals(this.system_packages, other.system_packages)) { return false; } return true; @@ -93,6 +99,7 @@ public int hashCode() { value = 31 * value + (this.storage_charge != null ? this.storage_charge.hashCode() : 0); value = 31 * value + (this.computation_charge != null ? this.computation_charge.hashCode() : 0); value = 31 * value + (this.storage_rebate != null ? this.storage_rebate.hashCode() : 0); + value = 31 * value + (this.non_refundable_storage_fee != null ? this.non_refundable_storage_fee.hashCode() : 0); value = 31 * value + (this.epoch_start_timestamp_ms != null ? this.epoch_start_timestamp_ms.hashCode() : 0); value = 31 * value + (this.system_packages != null ? this.system_packages.hashCode() : 0); return value; @@ -104,6 +111,7 @@ public static final class Builder { public @com.novi.serde.Unsigned Long storage_charge; public @com.novi.serde.Unsigned Long computation_charge; public @com.novi.serde.Unsigned Long storage_rebate; + public @com.novi.serde.Unsigned Long non_refundable_storage_fee; public @com.novi.serde.Unsigned Long epoch_start_timestamp_ms; public java.util.List>, java.util.List>> system_packages; @@ -114,6 +122,7 @@ public ChangeEpoch build() { storage_charge, computation_charge, storage_rebate, + non_refundable_storage_fee, epoch_start_timestamp_ms, system_packages ); diff --git a/src/main/java/io/sui/bcsgen/CommandArgumentError.java b/src/main/java/io/sui/bcsgen/CommandArgumentError.java index 1602e7b..b387460 100644 --- a/src/main/java/io/sui/bcsgen/CommandArgumentError.java +++ b/src/main/java/io/sui/bcsgen/CommandArgumentError.java @@ -16,10 +16,9 @@ public static CommandArgumentError deserialize(com.novi.serde.Deserializer deser case 5: return SecondaryIndexOutOfBounds.load(deserializer); case 6: return InvalidResultArity.load(deserializer); case 7: return InvalidGasCoinUsage.load(deserializer); - case 8: return InvalidUsageOfBorrowedValue.load(deserializer); - case 9: return InvalidUsageOfTakenValue.load(deserializer); - case 10: return InvalidObjectByValue.load(deserializer); - case 11: return InvalidObjectByMutRef.load(deserializer); + case 8: return InvalidValueUsage.load(deserializer); + case 9: return InvalidObjectByValue.load(deserializer); + case 10: return InvalidObjectByMutRef.load(deserializer); default: throw new com.novi.serde.DeserializationError("Unknown variant index for CommandArgumentError: " + index); } } @@ -388,8 +387,8 @@ public InvalidGasCoinUsage build() { } } - public static final class InvalidUsageOfBorrowedValue extends CommandArgumentError { - public InvalidUsageOfBorrowedValue() { + public static final class InvalidValueUsage extends CommandArgumentError { + public InvalidValueUsage() { } public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { @@ -398,7 +397,7 @@ public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serd serializer.decrease_container_depth(); } - static InvalidUsageOfBorrowedValue load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + static InvalidValueUsage load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { deserializer.increase_container_depth(); Builder builder = new Builder(); deserializer.decrease_container_depth(); @@ -409,7 +408,7 @@ public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; - InvalidUsageOfBorrowedValue other = (InvalidUsageOfBorrowedValue) obj; + InvalidValueUsage other = (InvalidValueUsage) obj; return true; } @@ -419,46 +418,8 @@ public int hashCode() { } public static final class Builder { - public InvalidUsageOfBorrowedValue build() { - return new InvalidUsageOfBorrowedValue( - ); - } - } - } - - public static final class InvalidUsageOfTakenValue extends CommandArgumentError { - public InvalidUsageOfTakenValue() { - } - - public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { - serializer.increase_container_depth(); - serializer.serialize_variant_index(9); - serializer.decrease_container_depth(); - } - - static InvalidUsageOfTakenValue load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - deserializer.increase_container_depth(); - Builder builder = new Builder(); - deserializer.decrease_container_depth(); - return builder.build(); - } - - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - InvalidUsageOfTakenValue other = (InvalidUsageOfTakenValue) obj; - return true; - } - - public int hashCode() { - int value = 7; - return value; - } - - public static final class Builder { - public InvalidUsageOfTakenValue build() { - return new InvalidUsageOfTakenValue( + public InvalidValueUsage build() { + return new InvalidValueUsage( ); } } @@ -470,7 +431,7 @@ public InvalidObjectByValue() { public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { serializer.increase_container_depth(); - serializer.serialize_variant_index(10); + serializer.serialize_variant_index(9); serializer.decrease_container_depth(); } @@ -508,7 +469,7 @@ public InvalidObjectByMutRef() { public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { serializer.increase_container_depth(); - serializer.serialize_variant_index(11); + serializer.serialize_variant_index(10); serializer.decrease_container_depth(); } diff --git a/src/main/java/io/sui/bcsgen/ExecutionFailureStatus.java b/src/main/java/io/sui/bcsgen/ExecutionFailureStatus.java index 1d12f95..073c5d5 100644 --- a/src/main/java/io/sui/bcsgen/ExecutionFailureStatus.java +++ b/src/main/java/io/sui/bcsgen/ExecutionFailureStatus.java @@ -36,6 +36,7 @@ public static ExecutionFailureStatus deserialize(com.novi.serde.Deserializer des case 25: return PublishUpgradeMissingDependency.load(deserializer); case 26: return PublishUpgradeDependencyDowngrade.load(deserializer); case 27: return PackageUpgradeError.load(deserializer); + case 28: return WrittenObjectsTooLarge.load(deserializer); default: throw new com.novi.serde.DeserializationError("Unknown variant index for ExecutionFailureStatus: " + index); } } @@ -1305,5 +1306,63 @@ public PackageUpgradeError build() { } } } + + public static final class WrittenObjectsTooLarge extends ExecutionFailureStatus { + public final @com.novi.serde.Unsigned Long current_size; + public final @com.novi.serde.Unsigned Long max_size; + + public WrittenObjectsTooLarge(@com.novi.serde.Unsigned Long current_size, @com.novi.serde.Unsigned Long max_size) { + java.util.Objects.requireNonNull(current_size, "current_size must not be null"); + java.util.Objects.requireNonNull(max_size, "max_size must not be null"); + this.current_size = current_size; + this.max_size = max_size; + } + + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + serializer.serialize_variant_index(28); + serializer.serialize_u64(current_size); + serializer.serialize_u64(max_size); + serializer.decrease_container_depth(); + } + + static WrittenObjectsTooLarge load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + builder.current_size = deserializer.deserialize_u64(); + builder.max_size = deserializer.deserialize_u64(); + deserializer.decrease_container_depth(); + return builder.build(); + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + WrittenObjectsTooLarge other = (WrittenObjectsTooLarge) obj; + if (!java.util.Objects.equals(this.current_size, other.current_size)) { return false; } + if (!java.util.Objects.equals(this.max_size, other.max_size)) { return false; } + return true; + } + + public int hashCode() { + int value = 7; + value = 31 * value + (this.current_size != null ? this.current_size.hashCode() : 0); + value = 31 * value + (this.max_size != null ? this.max_size.hashCode() : 0); + return value; + } + + public static final class Builder { + public @com.novi.serde.Unsigned Long current_size; + public @com.novi.serde.Unsigned Long max_size; + + public WrittenObjectsTooLarge build() { + return new WrittenObjectsTooLarge( + current_size, + max_size + ); + } + } + } } diff --git a/src/main/java/io/sui/bcsgen/MoveObjectType.java b/src/main/java/io/sui/bcsgen/MoveObjectType.java index eba1c98..2bc255b 100644 --- a/src/main/java/io/sui/bcsgen/MoveObjectType.java +++ b/src/main/java/io/sui/bcsgen/MoveObjectType.java @@ -1,19 +1,18 @@ package io.sui.bcsgen; -public abstract class MoveObjectType { +public final class MoveObjectType { + public final MoveObjectType_ value; - abstract public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError; + public MoveObjectType(MoveObjectType_ value) { + java.util.Objects.requireNonNull(value, "value must not be null"); + this.value = value; + } - public static MoveObjectType deserialize(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - int index = deserializer.deserialize_variant_index(); - switch (index) { - case 0: return Other.load(deserializer); - case 1: return GasCoin.load(deserializer); - case 2: return StakedSui.load(deserializer); - case 3: return Coin.load(deserializer); - default: throw new com.novi.serde.DeserializationError("Unknown variant index for MoveObjectType: " + index); - } + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + value.serialize(serializer); + serializer.decrease_container_depth(); } public byte[] bcsSerialize() throws com.novi.serde.SerializationError { @@ -22,6 +21,14 @@ public byte[] bcsSerialize() throws com.novi.serde.SerializationError { return serializer.get_bytes(); } + public static MoveObjectType deserialize(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + builder.value = MoveObjectType_.deserialize(deserializer); + deserializer.decrease_container_depth(); + return builder.build(); + } + public static MoveObjectType bcsDeserialize(byte[] input) throws com.novi.serde.DeserializationError { if (input == null) { throw new com.novi.serde.DeserializationError("Cannot deserialize null array"); @@ -34,178 +41,28 @@ public static MoveObjectType bcsDeserialize(byte[] input) throws com.novi.serde. return value; } - public static final class Other extends MoveObjectType { - public final StructTag value; - - public Other(StructTag value) { - java.util.Objects.requireNonNull(value, "value must not be null"); - this.value = value; - } - - public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { - serializer.increase_container_depth(); - serializer.serialize_variant_index(0); - value.serialize(serializer); - serializer.decrease_container_depth(); - } - - static Other load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - deserializer.increase_container_depth(); - Builder builder = new Builder(); - builder.value = StructTag.deserialize(deserializer); - deserializer.decrease_container_depth(); - return builder.build(); - } - - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - Other other = (Other) obj; - if (!java.util.Objects.equals(this.value, other.value)) { return false; } - return true; - } - - public int hashCode() { - int value = 7; - value = 31 * value + (this.value != null ? this.value.hashCode() : 0); - return value; - } - - public static final class Builder { - public StructTag value; - - public Other build() { - return new Other( - value - ); - } - } - } - - public static final class GasCoin extends MoveObjectType { - public GasCoin() { - } - - public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { - serializer.increase_container_depth(); - serializer.serialize_variant_index(1); - serializer.decrease_container_depth(); - } - - static GasCoin load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - deserializer.increase_container_depth(); - Builder builder = new Builder(); - deserializer.decrease_container_depth(); - return builder.build(); - } - - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - GasCoin other = (GasCoin) obj; - return true; - } - - public int hashCode() { - int value = 7; - return value; - } - - public static final class Builder { - public GasCoin build() { - return new GasCoin( - ); - } - } + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + MoveObjectType other = (MoveObjectType) obj; + if (!java.util.Objects.equals(this.value, other.value)) { return false; } + return true; } - public static final class StakedSui extends MoveObjectType { - public StakedSui() { - } - - public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { - serializer.increase_container_depth(); - serializer.serialize_variant_index(2); - serializer.decrease_container_depth(); - } - - static StakedSui load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - deserializer.increase_container_depth(); - Builder builder = new Builder(); - deserializer.decrease_container_depth(); - return builder.build(); - } - - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - StakedSui other = (StakedSui) obj; - return true; - } - - public int hashCode() { - int value = 7; - return value; - } - - public static final class Builder { - public StakedSui build() { - return new StakedSui( - ); - } - } + public int hashCode() { + int value = 7; + value = 31 * value + (this.value != null ? this.value.hashCode() : 0); + return value; } - public static final class Coin extends MoveObjectType { - public final TypeTag value; - - public Coin(TypeTag value) { - java.util.Objects.requireNonNull(value, "value must not be null"); - this.value = value; - } - - public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { - serializer.increase_container_depth(); - serializer.serialize_variant_index(3); - value.serialize(serializer); - serializer.decrease_container_depth(); - } - - static Coin load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { - deserializer.increase_container_depth(); - Builder builder = new Builder(); - builder.value = TypeTag.deserialize(deserializer); - deserializer.decrease_container_depth(); - return builder.build(); - } - - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - Coin other = (Coin) obj; - if (!java.util.Objects.equals(this.value, other.value)) { return false; } - return true; - } + public static final class Builder { + public MoveObjectType_ value; - public int hashCode() { - int value = 7; - value = 31 * value + (this.value != null ? this.value.hashCode() : 0); - return value; - } - - public static final class Builder { - public TypeTag value; - - public Coin build() { - return new Coin( - value - ); - } + public MoveObjectType build() { + return new MoveObjectType( + value + ); } } } - diff --git a/src/main/java/io/sui/bcsgen/MoveObjectType_.java b/src/main/java/io/sui/bcsgen/MoveObjectType_.java new file mode 100644 index 0000000..2028eac --- /dev/null +++ b/src/main/java/io/sui/bcsgen/MoveObjectType_.java @@ -0,0 +1,211 @@ +package io.sui.bcsgen; + + +public abstract class MoveObjectType_ { + + abstract public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError; + + public static MoveObjectType_ deserialize(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + int index = deserializer.deserialize_variant_index(); + switch (index) { + case 0: return Other.load(deserializer); + case 1: return GasCoin.load(deserializer); + case 2: return StakedSui.load(deserializer); + case 3: return Coin.load(deserializer); + default: throw new com.novi.serde.DeserializationError("Unknown variant index for MoveObjectType_: " + index); + } + } + + public byte[] bcsSerialize() throws com.novi.serde.SerializationError { + com.novi.serde.Serializer serializer = new com.novi.bcs.BcsSerializer(); + serialize(serializer); + return serializer.get_bytes(); + } + + public static MoveObjectType_ bcsDeserialize(byte[] input) throws com.novi.serde.DeserializationError { + if (input == null) { + throw new com.novi.serde.DeserializationError("Cannot deserialize null array"); + } + com.novi.serde.Deserializer deserializer = new com.novi.bcs.BcsDeserializer(input); + MoveObjectType_ value = deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.length) { + throw new com.novi.serde.DeserializationError("Some input bytes were not read"); + } + return value; + } + + public static final class Other extends MoveObjectType_ { + public final StructTag value; + + public Other(StructTag value) { + java.util.Objects.requireNonNull(value, "value must not be null"); + this.value = value; + } + + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + serializer.serialize_variant_index(0); + value.serialize(serializer); + serializer.decrease_container_depth(); + } + + static Other load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + builder.value = StructTag.deserialize(deserializer); + deserializer.decrease_container_depth(); + return builder.build(); + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + Other other = (Other) obj; + if (!java.util.Objects.equals(this.value, other.value)) { return false; } + return true; + } + + public int hashCode() { + int value = 7; + value = 31 * value + (this.value != null ? this.value.hashCode() : 0); + return value; + } + + public static final class Builder { + public StructTag value; + + public Other build() { + return new Other( + value + ); + } + } + } + + public static final class GasCoin extends MoveObjectType_ { + public GasCoin() { + } + + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + serializer.serialize_variant_index(1); + serializer.decrease_container_depth(); + } + + static GasCoin load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + deserializer.decrease_container_depth(); + return builder.build(); + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + GasCoin other = (GasCoin) obj; + return true; + } + + public int hashCode() { + int value = 7; + return value; + } + + public static final class Builder { + public GasCoin build() { + return new GasCoin( + ); + } + } + } + + public static final class StakedSui extends MoveObjectType_ { + public StakedSui() { + } + + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + serializer.serialize_variant_index(2); + serializer.decrease_container_depth(); + } + + static StakedSui load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + deserializer.decrease_container_depth(); + return builder.build(); + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + StakedSui other = (StakedSui) obj; + return true; + } + + public int hashCode() { + int value = 7; + return value; + } + + public static final class Builder { + public StakedSui build() { + return new StakedSui( + ); + } + } + } + + public static final class Coin extends MoveObjectType_ { + public final TypeTag value; + + public Coin(TypeTag value) { + java.util.Objects.requireNonNull(value, "value must not be null"); + this.value = value; + } + + public void serialize(com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError { + serializer.increase_container_depth(); + serializer.serialize_variant_index(3); + value.serialize(serializer); + serializer.decrease_container_depth(); + } + + static Coin load(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError { + deserializer.increase_container_depth(); + Builder builder = new Builder(); + builder.value = TypeTag.deserialize(deserializer); + deserializer.decrease_container_depth(); + return builder.build(); + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + Coin other = (Coin) obj; + if (!java.util.Objects.equals(this.value, other.value)) { return false; } + return true; + } + + public int hashCode() { + int value = 7; + value = 31 * value + (this.value != null ? this.value.hashCode() : 0); + return value; + } + + public static final class Builder { + public TypeTag value; + + public Coin build() { + return new Coin( + value + ); + } + } + } +} + diff --git a/src/main/java/io/sui/clients/EventClient.java b/src/main/java/io/sui/clients/EventClient.java index 4e0ac0e..b26651b 100644 --- a/src/main/java/io/sui/clients/EventClient.java +++ b/src/main/java/io/sui/clients/EventClient.java @@ -20,8 +20,8 @@ import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.functions.Consumer; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; import io.sui.models.events.EventFilter; +import io.sui.models.events.SuiEvent; /** * The interface Event client. @@ -40,5 +40,5 @@ public interface EventClient { * @return the disposable */ Disposable subscribeEvent( - EventFilter eventFilter, Consumer onNext, Consumer onError); + EventFilter eventFilter, Consumer onNext, Consumer onError); } diff --git a/src/main/java/io/sui/clients/EventClientImpl.java b/src/main/java/io/sui/clients/EventClientImpl.java index 4fa4896..3a58dcc 100644 --- a/src/main/java/io/sui/clients/EventClientImpl.java +++ b/src/main/java/io/sui/clients/EventClientImpl.java @@ -23,8 +23,8 @@ import io.sui.jsonrpc.JsonRpc20Request; import io.sui.jsonrpc.JsonRpcClientProvider; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; import io.sui.models.events.EventFilter; +import io.sui.models.events.SuiEvent; /** * The type Event client. @@ -42,10 +42,10 @@ public EventClientImpl(JsonRpcClientProvider jsonRpcClientProvider) { @Override public Disposable subscribeEvent( - EventFilter eventFilter, Consumer onNext, Consumer onError) { + EventFilter eventFilter, Consumer onNext, Consumer onError) { final JsonRpc20Request request = this.jsonRpcClientProvider.createJsonRpc20Request( - "sui_subscribeEvent", Lists.newArrayList(eventFilter)); + "suix_subscribeEvent", Lists.newArrayList(eventFilter)); return this.jsonRpcClientProvider.subscribe(request, onNext, onError); } } diff --git a/src/main/java/io/sui/clients/GasBudgetLessThanGasPriceException.java b/src/main/java/io/sui/clients/GasBudgetLessThanGasPriceException.java new file mode 100644 index 0000000..131d024 --- /dev/null +++ b/src/main/java/io/sui/clients/GasBudgetLessThanGasPriceException.java @@ -0,0 +1,40 @@ +/* + * Copyright 2023 281165273grape@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package io.sui.clients; + +/** + * The type Gas budget less than gas price exception. + * + * @author grapebaba + * @since 2023.04 + */ +public class GasBudgetLessThanGasPriceException extends RuntimeException { + + /** + * Instantiates a new Gas budget less than gas price exception. + * + * @param gasBudget the gas budget + * @param gasPrice the gas price + */ + public GasBudgetLessThanGasPriceException(Long gasBudget, Long gasPrice) { + super( + String.format( + "Gas budget %d is less than the reference gas price %d. The gas budget must be at least" + + " the current reference gas price of %d.", + gasBudget, gasPrice, gasPrice)); + } +} diff --git a/src/main/java/io/sui/clients/LocalTransactionBuilder.java b/src/main/java/io/sui/clients/LocalTransactionBuilder.java index f8c5091..bcb1091 100644 --- a/src/main/java/io/sui/clients/LocalTransactionBuilder.java +++ b/src/main/java/io/sui/clients/LocalTransactionBuilder.java @@ -1129,7 +1129,7 @@ private CompletableFuture selectGas( objectDataOptions.setShowBcs(true); objectResponseQuery.setOptions(objectDataOptions); return queryClient - .getObjectsOwnedByAddress(signer, objectResponseQuery, null, null, null) + .getObjectsOwnedByAddress(signer, objectResponseQuery, null, null) .thenCompose( (Function>) paginatedObjectsResponse -> { @@ -1546,7 +1546,7 @@ private Tuple3 getObjectRef(SuiObjectRef objectIdBuilder.value = coinAddressBuilder.build(); SequenceNumber.Builder sequenceNumberBuilder = new SequenceNumber.Builder(); - sequenceNumberBuilder.value = objRef.getVersion(); + sequenceNumberBuilder.value = objRef.getVersion().longValue(); Digest.Builder digestBuilder = new Digest.Builder(); digestBuilder.value = Bytes.valueOf(Base58.decode(objRef.getDigest())); ObjectDigest.Builder objectDigestBuilder = new ObjectDigest.Builder(); diff --git a/src/main/java/io/sui/clients/QueryClient.java b/src/main/java/io/sui/clients/QueryClient.java index 3169fd7..2680032 100644 --- a/src/main/java/io/sui/clients/QueryClient.java +++ b/src/main/java/io/sui/clients/QueryClient.java @@ -73,11 +73,10 @@ public interface QueryClient { * @param query the query * @param cursor the cursor * @param limit the limit - * @param checkpointId the checkpoint id * @return the objects owned by address */ CompletableFuture getObjectsOwnedByAddress( - String address, ObjectResponseQuery query, String cursor, Integer limit, String checkpointId); + String address, ObjectResponseQuery query, String cursor, Integer limit); /** * Gets total transaction number. @@ -106,6 +105,13 @@ CompletableFuture getTransactionBlock( CompletableFuture> multiGetTransactionBlocks( List digests, TransactionBlockResponseOptions options); + /** + * Multi get objects completable future. + * + * @param objectIds the object ids + * @param options the options + * @return the completable future + */ CompletableFuture> multiGetObjects( List objectIds, ObjectDataOptions options); @@ -215,6 +221,17 @@ CompletableFuture getNormalizedMoveStruct( CompletableFuture queryTransactionBlocks( TransactionBlockResponseQuery query, String cursor, Integer limit, boolean isDescOrder); + /** + * Query objects completable future. + * + * @param query the query + * @param cursor the cursor + * @param limit the limit + * @return the completable future + */ + CompletableFuture queryObjects( + ObjectResponseQuery query, String cursor, Integer limit); + /** * Gets coin metadata. * @@ -255,7 +272,7 @@ CompletableFuture queryTransactionBlocks( * @param limit the limit * @return all Coin objects owned by the address. */ - CompletableFuture getAllCoins(String address, String cursor, long limit); + CompletableFuture getAllCoins(String address, String cursor, Integer limit); /** * Return all Coin with coin_type objects owned by an address. diff --git a/src/main/java/io/sui/clients/QueryClientImpl.java b/src/main/java/io/sui/clients/QueryClientImpl.java index f800dd4..c827d9e 100644 --- a/src/main/java/io/sui/clients/QueryClientImpl.java +++ b/src/main/java/io/sui/clients/QueryClientImpl.java @@ -87,15 +87,10 @@ public CompletableFuture getObjectRef( @Override public CompletableFuture getObjectsOwnedByAddress( - String address, - ObjectResponseQuery query, - String cursor, - Integer limit, - String checkpointId) { + String address, ObjectResponseQuery query, String cursor, Integer limit) { final JsonRpc20Request request = this.jsonRpcClientProvider.createJsonRpc20Request( - "suix_getOwnedObjects", - Lists.newArrayList(address, query, cursor, limit, checkpointId)); + "suix_getOwnedObjects", Lists.newArrayList(address, query, cursor, limit)); return this.jsonRpcClientProvider.callAndUnwrapResponse( "/suix_getOwnedObjects", request, new TypeToken() {}.getType()); } @@ -261,6 +256,16 @@ public CompletableFuture queryTransactionBlocks( new TypeToken() {}.getType()); } + @Override + public CompletableFuture queryObjects( + ObjectResponseQuery query, String cursor, Integer limit) { + final JsonRpc20Request request = + this.jsonRpcClientProvider.createJsonRpc20Request( + "suix_queryObjects", Lists.newArrayList(query, cursor, limit)); + return this.jsonRpcClientProvider.callAndUnwrapResponse( + "/suix_queryObjects", request, new TypeToken() {}.getType()); + } + @Override public CompletableFuture getCoinMetadata(String coinType) { final JsonRpc20Request request = @@ -289,12 +294,13 @@ public CompletableFuture> getAllBalances(String address) { } @Override - public CompletableFuture getAllCoins(String address, String cursor, long limit) { + public CompletableFuture getAllCoins( + String address, String cursor, Integer limit) { final JsonRpc20Request request = this.jsonRpcClientProvider.createJsonRpc20Request( - "sui_getAllCoins", Lists.newArrayList(address, cursor, limit)); + "suix_getAllCoins", Lists.newArrayList(address, cursor, limit)); return this.jsonRpcClientProvider.callAndUnwrapResponse( - "/sui_getAllCoins", request, new TypeToken() {}.getType()); + "/suix_getAllCoins", request, new TypeToken() {}.getType()); } @Override @@ -317,9 +323,9 @@ public CompletableFuture getBalance(String address, String coinType) { } final JsonRpc20Request request = this.jsonRpcClientProvider.createJsonRpc20Request( - "sui_getBalance", Lists.newArrayList(address, coinType)); + "suix_getBalance", Lists.newArrayList(address, coinType)); return this.jsonRpcClientProvider.callAndUnwrapResponse( - "/sui_getBalance", request, new TypeToken() {}.getType()); + "/suix_getBalance", request, new TypeToken() {}.getType()); } @Override diff --git a/src/main/java/io/sui/clients/TransactionBlock.java b/src/main/java/io/sui/clients/TransactionBlock.java index 807232a..79c7ab2 100644 --- a/src/main/java/io/sui/clients/TransactionBlock.java +++ b/src/main/java/io/sui/clients/TransactionBlock.java @@ -614,6 +614,9 @@ public Argument pure(Object value) { @SuppressWarnings("unchecked") private CompletableFuture selectGas( String signer, Long budget, Long gasPrice, List excludeObjects) { + if (budget < gasPrice) { + throw new GasBudgetLessThanGasPriceException(budget, gasPrice); + } final ObjectResponseQuery objectResponseQuery = new ObjectResponseQuery(); ObjectDataOptions objectDataOptions = new ObjectDataOptions(); objectDataOptions.setShowPreviousTransaction(true); @@ -623,7 +626,7 @@ private CompletableFuture selectGas( objectDataOptions.setShowBcs(true); objectResponseQuery.setOptions(objectDataOptions); return queryClient - .getObjectsOwnedByAddress(signer, objectResponseQuery, null, null, null) + .getObjectsOwnedByAddress(signer, objectResponseQuery, null, null) .thenCompose( (Function>) paginatedObjectsResponse -> { @@ -648,14 +651,10 @@ private CompletableFuture selectGas( } catch (DeserializationError e) { throw new BcsSerializationException(e); } - final long requiredGasAmount = - BigInteger.valueOf(budget) - .multiply(BigInteger.valueOf(gasPrice)) - .longValue(); if (!excludeObjects.contains( objectResponse.getData().getObjectId()) - && gasCoin.value.balance.value >= requiredGasAmount) { + && gasCoin.value.balance.value >= budget) { return CompletableFuture.completedFuture( Optional.of(objectResponse.getData().getRef())); } @@ -1000,7 +999,10 @@ private CompletableFuture newObjectArg(String objectId, boolean mutab objectIdBuilder.value = accountAddressBuilder.build(); SequenceNumber.Builder seqBuilder = new SequenceNumber.Builder(); seqBuilder.value = - ((SuiObjectOwner.SharedOwner) owner).getShared().getInitial_shared_version(); + ((SuiObjectOwner.SharedOwner) owner) + .getShared() + .getInitial_shared_version() + .longValue(); SharedObject.Builder sharedObjectBuilder = new SharedObject.Builder(); sharedObjectBuilder.id = objectIdBuilder.build(); sharedObjectBuilder.initial_shared_version = seqBuilder.build(); @@ -1060,7 +1062,7 @@ private Tuple3 getObjectRef(SuiObjectRef objectIdBuilder.value = addressBuilder.build(); SequenceNumber.Builder sequenceNumberBuilder = new SequenceNumber.Builder(); - sequenceNumberBuilder.value = objRef.getVersion(); + sequenceNumberBuilder.value = objRef.getVersion().longValue(); Digest.Builder digestBuilder = new Digest.Builder(); digestBuilder.value = Bytes.valueOf(Base58.decode(objRef.getDigest())); ObjectDigest.Builder objectDigestBuilder = new ObjectDigest.Builder(); diff --git a/src/main/java/io/sui/crypto/SigningException.java b/src/main/java/io/sui/crypto/SigningException.java index abd6bd3..ff9b326 100644 --- a/src/main/java/io/sui/crypto/SigningException.java +++ b/src/main/java/io/sui/crypto/SigningException.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -22,7 +22,7 @@ * @author grapebaba * @since 2022.11 */ -public class SigningException extends Exception { +public class SigningException extends RuntimeException { /** * Instantiates a new Signing exception. diff --git a/src/main/java/io/sui/jsonrpc/GsonJsonHandler.java b/src/main/java/io/sui/jsonrpc/GsonJsonHandler.java index d9f9f2e..898aab4 100644 --- a/src/main/java/io/sui/jsonrpc/GsonJsonHandler.java +++ b/src/main/java/io/sui/jsonrpc/GsonJsonHandler.java @@ -29,6 +29,7 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.ToNumberPolicy; +import com.google.gson.internal.bind.TypeAdapters; import com.google.gson.reflect.TypeToken; import io.sui.models.FaucetResponse; import io.sui.models.events.EventFilter; @@ -92,6 +93,7 @@ import io.sui.models.transactions.TypeTag.StructType; import io.sui.models.transactions.TypeTag.VectorType; import java.lang.reflect.Type; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -274,9 +276,9 @@ public ObjectResponse deserialize( } else if (json.getAsJsonObject() .get("status") .getAsString() - .equals(ObjectStatus.NotExists.name())) { + .equals(ObjectStatus.notExists.name())) { ObjectResponse objectResponse = new ObjectResponse(); - objectResponse.setStatus(ObjectStatus.NotExists); + objectResponse.setStatus(ObjectStatus.notExists); objectResponse.setDetails( gson.fromJson( json.getAsJsonObject().get("details"), @@ -767,6 +769,7 @@ EventFilter.PackageEventFilter.class, new PackageEventFilterSerializer()) .registerTypeAdapter(Command.class, new SuiCommandDeserializer()) .registerTypeAdapter(ObjectChange.class, new ObjectChangeDeserializer()) .registerTypeAdapter(SuiParsedData.class, new SuiParsedDataDeserializer()) + .registerTypeAdapter(BigInteger.class, TypeAdapters.BIG_INTEGER) .create(); } diff --git a/src/main/java/io/sui/jsonrpc/JsonRpc20WSResponse.java b/src/main/java/io/sui/jsonrpc/JsonRpc20WSResponse.java index c3c557a..a6f6fa6 100644 --- a/src/main/java/io/sui/jsonrpc/JsonRpc20WSResponse.java +++ b/src/main/java/io/sui/jsonrpc/JsonRpc20WSResponse.java @@ -17,7 +17,7 @@ package io.sui.jsonrpc; -import io.sui.models.events.EventEnvelope; +import io.sui.models.events.SuiEvent; import java.util.Objects; /** @@ -34,7 +34,7 @@ public static class Params { private Long subscription; - private EventEnvelope result; + private SuiEvent result; /** * Gets subscription. @@ -59,7 +59,7 @@ public void setSubscription(Long subscription) { * * @return the result */ - public EventEnvelope getResult() { + public SuiEvent getResult() { return result; } @@ -68,7 +68,7 @@ public EventEnvelope getResult() { * * @param result the result */ - public void setResult(EventEnvelope result) { + public void setResult(SuiEvent result) { this.result = result; } diff --git a/src/main/java/io/sui/jsonrpc/JsonRpcClientProvider.java b/src/main/java/io/sui/jsonrpc/JsonRpcClientProvider.java index fa4de36..ae3a818 100644 --- a/src/main/java/io/sui/jsonrpc/JsonRpcClientProvider.java +++ b/src/main/java/io/sui/jsonrpc/JsonRpcClientProvider.java @@ -20,7 +20,7 @@ import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.functions.Consumer; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; +import io.sui.models.events.SuiEvent; import java.lang.reflect.Type; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -47,7 +47,7 @@ private long nextId() { } public abstract Disposable subscribe( - JsonRpc20Request request, Consumer onNext, Consumer onError); + JsonRpc20Request request, Consumer onNext, Consumer onError); /** * Call completable future. diff --git a/src/main/java/io/sui/jsonrpc/OkHttpJsonRpcClientProvider.java b/src/main/java/io/sui/jsonrpc/OkHttpJsonRpcClientProvider.java index cbee0e1..b6ab35c 100644 --- a/src/main/java/io/sui/jsonrpc/OkHttpJsonRpcClientProvider.java +++ b/src/main/java/io/sui/jsonrpc/OkHttpJsonRpcClientProvider.java @@ -26,7 +26,7 @@ import io.sui.jsonrpc.JsonRpc20Response.Error; import io.sui.jsonrpc.JsonRpc20Response.Error.ErrorCode; import io.sui.models.SuiApiException; -import io.sui.models.events.EventEnvelope; +import io.sui.models.events.SuiEvent; import java.io.IOException; import java.lang.reflect.Type; import java.time.Duration; @@ -166,7 +166,7 @@ public void onOpen(WebSocket webSocket, Response response) { @SuppressWarnings("checkstyle:Indentation") @Override public Disposable subscribe( - JsonRpc20Request request, Consumer onNext, Consumer onError) { + JsonRpc20Request request, Consumer onNext, Consumer onError) { final String subscribeRequestBodyJsonStr = this.jsonHandler.toJson(request); System.out.println(subscribeRequestBodyJsonStr); final CompletableFuture subscriptionResponseFuture = new CompletableFuture<>(); @@ -266,10 +266,10 @@ public void onResponse(Call call, Response response) { return future; } - private void unsubscribe(JsonRpc20Request request) throws IOException { + private void unsubscribe(JsonRpc20Request request) { final Long subscriptionId = requestIdToSubscriptionIds.get(request.getId()); final JsonRpc20Request unsubscribeRequest = - createJsonRpc20Request("sui_unsubscribeEvent", Lists.newArrayList(subscriptionId)); + createJsonRpc20Request("suix_unsubscribeEvent", Lists.newArrayList(subscriptionId)); final String unsubscribeRequestBodyJsonStr = jsonHandler.toJson(unsubscribeRequest); final CompletableFuture unsubscribeResultFuture = new CompletableFuture<>(); requestIdToReplies.put(unsubscribeRequest.getId(), unsubscribeResultFuture); diff --git a/src/main/java/io/sui/models/events/EventFilter.java b/src/main/java/io/sui/models/events/EventFilter.java index 61b3823..c5ed600 100644 --- a/src/main/java/io/sui/models/events/EventFilter.java +++ b/src/main/java/io/sui/models/events/EventFilter.java @@ -18,6 +18,7 @@ import com.google.common.collect.Lists; +import io.sui.models.objects.MoveModule; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -146,19 +147,66 @@ public String toString() { } } + /** The type Transaction event filter. */ + public static class TransactionEventFilter extends EventFilter { + + @SuppressWarnings("checkstyle:MemberName") + private String Transaction; + + /** + * Gets transaction. + * + * @return the transaction + */ + public String getTransaction() { + return Transaction; + } + + /** + * Sets transaction. + * + * @param transaction the transaction + */ + public void setTransaction(String transaction) { + Transaction = transaction; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TransactionEventFilter)) { + return false; + } + TransactionEventFilter that = (TransactionEventFilter) o; + return Transaction.equals(that.Transaction); + } + + @Override + public int hashCode() { + return Objects.hash(Transaction); + } + + @Override + public String toString() { + return "TransactionEventFilter{" + "Transaction='" + Transaction + '\'' + '}'; + } + } + /** The type Module event filter. */ - public static class ModuleEventFilter extends EventFilter { + public static class MoveModuleEventFilter extends EventFilter { @SuppressWarnings("checkstyle:MemberName") - private String Module; + private MoveModule MoveModule; /** * Gets module. * * @return the module */ - public String getModule() { - return Module; + public MoveModule getModule() { + return MoveModule; } /** @@ -166,8 +214,8 @@ public String getModule() { * * @param module the module */ - public void setModule(String module) { - Module = module; + public void setModule(MoveModule module) { + MoveModule = module; } @Override @@ -175,21 +223,21 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof ModuleEventFilter)) { + if (!(o instanceof MoveModuleEventFilter)) { return false; } - ModuleEventFilter moduleEventFilter = (ModuleEventFilter) o; - return Module.equals(moduleEventFilter.Module); + MoveModuleEventFilter moveModuleEventFilter = (MoveModuleEventFilter) o; + return MoveModule.equals(moveModuleEventFilter.MoveModule); } @Override public int hashCode() { - return Objects.hash(Module); + return Objects.hash(MoveModule); } @Override public String toString() { - return "Module{" + "Module='" + Module + '\'' + '}'; + return "MoveModule{" + "MoveModule='" + MoveModule + '\'' + '}'; } } @@ -291,24 +339,24 @@ public String toString() { public static class SenderAddressEventFilter extends EventFilter { @SuppressWarnings("checkstyle:MemberName") - private String SenderAddress; + private String Sender; /** * Gets sender address. * * @return the sender address */ - public String getSenderAddress() { - return SenderAddress; + public String getSender() { + return Sender; } /** * Sets sender address. * - * @param senderAddress the sender address + * @param sender the sender address */ - public void setSenderAddress(String senderAddress) { - SenderAddress = senderAddress; + public void setSender(String sender) { + Sender = sender; } @Override @@ -320,64 +368,17 @@ public boolean equals(Object o) { return false; } SenderAddressEventFilter that = (SenderAddressEventFilter) o; - return SenderAddress.equals(that.SenderAddress); + return Sender.equals(that.Sender); } @Override public int hashCode() { - return Objects.hash(SenderAddress); + return Objects.hash(Sender); } @Override public String toString() { - return "SenderAddressEventFilter{" + "SenderAddress='" + SenderAddress + '\'' + '}'; - } - } - - /** The type Event type event filter. */ - public static class EventTypeEventFilter extends EventFilter { - - @SuppressWarnings("checkstyle:MemberName") - private EventType EventType; - - /** - * Gets event type. - * - * @return the event type - */ - public EventType getEventType() { - return EventType; - } - - /** - * Sets event type. - * - * @param eventType the event type - */ - public void setEventType(EventType eventType) { - EventType = eventType; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof EventTypeEventFilter)) { - return false; - } - EventTypeEventFilter that = (EventTypeEventFilter) o; - return EventType == that.EventType; - } - - @Override - public int hashCode() { - return Objects.hash(EventType); - } - - @Override - public String toString() { - return "EventTypeEventFilter{" + "EventType=" + EventType + '}'; + return "SenderAddressEventFilter{" + "SenderAddress='" + Sender + '\'' + '}'; } } @@ -550,4 +551,121 @@ public String toString() { return "OrEventFilter{" + "Or=" + Arrays.toString(Or) + '}'; } } + + /** The type Time range filter. */ + public static class TimeRangeFilter extends EventFilter { + + /** The type Time range. */ + public static class TimeRange { + + @SuppressWarnings("checkstyle:MemberName") + private Long start_time; + + @SuppressWarnings("checkstyle:MemberName") + private Long end_time; + + /** + * Gets start time. + * + * @return the start time + */ + public Long getStart_time() { + return start_time; + } + + /** + * Sets start time. + * + * @param start_time the start time + */ + @SuppressWarnings("checkstyle:ParameterName") + public void setStart_time(Long start_time) { + this.start_time = start_time; + } + + /** + * Gets end time. + * + * @return the end time + */ + public Long getEnd_time() { + return end_time; + } + + /** + * Sets end time. + * + * @param end_time the end time + */ + @SuppressWarnings("checkstyle:ParameterName") + public void setEnd_time(Long end_time) { + this.end_time = end_time; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TimeRange)) { + return false; + } + TimeRange timeRange = (TimeRange) o; + return start_time.equals(timeRange.start_time) && end_time.equals(timeRange.end_time); + } + + @Override + public int hashCode() { + return Objects.hash(start_time, end_time); + } + + @Override + public String toString() { + return "TimeRange{" + "start_time=" + start_time + ", end_time=" + end_time + '}'; + } + } + + @SuppressWarnings("checkstyle:MemberName") + private TimeRange TimeRange; + + /** + * Gets time range. + * + * @return the time range + */ + public TimeRangeFilter.TimeRange getTimeRange() { + return TimeRange; + } + + /** + * Sets time range. + * + * @param timeRange the time range + */ + public void setTimeRange(TimeRangeFilter.TimeRange timeRange) { + TimeRange = timeRange; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TimeRangeFilter)) { + return false; + } + TimeRangeFilter that = (TimeRangeFilter) o; + return TimeRange.equals(that.TimeRange); + } + + @Override + public int hashCode() { + return Objects.hash(TimeRange); + } + + @Override + public String toString() { + return "TimeRangeFilter{" + "TimeRange=" + TimeRange + '}'; + } + } } diff --git a/src/main/java/io/sui/models/events/EventId.java b/src/main/java/io/sui/models/events/EventId.java index 381b5ff..ad4b75a 100644 --- a/src/main/java/io/sui/models/events/EventId.java +++ b/src/main/java/io/sui/models/events/EventId.java @@ -17,6 +17,7 @@ package io.sui.models.events; +import java.math.BigInteger; import java.util.Objects; /** @@ -29,14 +30,14 @@ public class EventId { private String txDigest; - private Long eventSeq; + private BigInteger eventSeq; /** * Gets event seq. * * @return the event seq */ - public Long getEventSeq() { + public BigInteger getEventSeq() { return eventSeq; } @@ -45,7 +46,7 @@ public Long getEventSeq() { * * @param eventSeq the event seq */ - public void setEventSeq(Long eventSeq) { + public void setEventSeq(BigInteger eventSeq) { this.eventSeq = eventSeq; } diff --git a/src/main/java/io/sui/models/events/SuiEvent.java b/src/main/java/io/sui/models/events/SuiEvent.java index 03c9a51..d13a081 100644 --- a/src/main/java/io/sui/models/events/SuiEvent.java +++ b/src/main/java/io/sui/models/events/SuiEvent.java @@ -17,6 +17,7 @@ package io.sui.models.events; +import java.math.BigInteger; import java.util.Map; import java.util.Objects; @@ -42,7 +43,7 @@ public class SuiEvent { private String bcs; - private Long timestampMs; + private BigInteger timestampMs; /** * Gets id. @@ -175,7 +176,7 @@ public void setBcs(String bcs) { * * @return the timestamp ms */ - public Long getTimestampMs() { + public BigInteger getTimestampMs() { return timestampMs; } @@ -184,7 +185,7 @@ public Long getTimestampMs() { * * @param timestampMs the timestamp ms */ - public void setTimestampMs(Long timestampMs) { + public void setTimestampMs(BigInteger timestampMs) { this.timestampMs = timestampMs; } diff --git a/src/main/java/io/sui/models/objects/Balance.java b/src/main/java/io/sui/models/objects/Balance.java index 3f6169a..1ec5090 100644 --- a/src/main/java/io/sui/models/objects/Balance.java +++ b/src/main/java/io/sui/models/objects/Balance.java @@ -35,7 +35,7 @@ public class Balance { private BigInteger totalBalance; - private Map lockedBalance; + private Map lockedBalance; public String getCoinType() { return coinType; @@ -61,11 +61,11 @@ public void setTotalBalance(BigInteger totalBalance) { this.totalBalance = totalBalance; } - public Map getLockedBalance() { + public Map getLockedBalance() { return lockedBalance; } - public void setLockedBalance(Map lockedBalance) { + public void setLockedBalance(Map lockedBalance) { this.lockedBalance = lockedBalance; } diff --git a/src/main/java/io/sui/models/objects/Coin.java b/src/main/java/io/sui/models/objects/Coin.java index 7e1a0c3..3ad4d67 100644 --- a/src/main/java/io/sui/models/objects/Coin.java +++ b/src/main/java/io/sui/models/objects/Coin.java @@ -18,6 +18,7 @@ import com.google.common.base.Objects; +import java.math.BigInteger; /** * the coin info. @@ -31,13 +32,13 @@ public class Coin { private String coinObjectId; - private Long version; + private BigInteger version; private String digest; - private Long balance; + private BigInteger balance; - private String lockedUtilEpoch; + private BigInteger lockedUtilEpoch; private String previousTransaction; @@ -57,11 +58,11 @@ public void setCoinObjectId(String coinObjectId) { this.coinObjectId = coinObjectId; } - public Long getVersion() { + public BigInteger getVersion() { return version; } - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -73,19 +74,19 @@ public void setDigest(String digest) { this.digest = digest; } - public Long getBalance() { + public BigInteger getBalance() { return balance; } - public void setBalance(Long balance) { + public void setBalance(BigInteger balance) { this.balance = balance; } - public String getLockedUtilEpoch() { + public BigInteger getLockedUtilEpoch() { return lockedUtilEpoch; } - public void setLockedUtilEpoch(String lockedUtilEpoch) { + public void setLockedUtilEpoch(BigInteger lockedUtilEpoch) { this.lockedUtilEpoch = lockedUtilEpoch; } diff --git a/src/main/java/io/sui/models/objects/DisplayFieldsResponse.java b/src/main/java/io/sui/models/objects/DisplayFieldsResponse.java new file mode 100644 index 0000000..f2a5c89 --- /dev/null +++ b/src/main/java/io/sui/models/objects/DisplayFieldsResponse.java @@ -0,0 +1,92 @@ +/* + * Copyright 2023 281165273grape@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package io.sui.models.objects; + + +import java.util.Map; +import java.util.Objects; + +/** + * The type Display fields response. + * + * @author grapebaba + * @since 2023.04 + */ +public class DisplayFieldsResponse { + + private Map data; + + private SuiObjectResponseError error; + + /** + * Gets data. + * + * @return the data + */ + public Map getData() { + return data; + } + + /** + * Sets data. + * + * @param data the data + */ + public void setData(Map data) { + this.data = data; + } + + /** + * Gets error. + * + * @return the error + */ + public SuiObjectResponseError getError() { + return error; + } + + /** + * Sets error. + * + * @param error the error + */ + public void setError(SuiObjectResponseError error) { + this.error = error; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DisplayFieldsResponse)) { + return false; + } + DisplayFieldsResponse that = (DisplayFieldsResponse) o; + return data.equals(that.data) && error.equals(that.error); + } + + @Override + public int hashCode() { + return Objects.hash(data, error); + } + + @Override + public String toString() { + return "DisplayFieldsResponse{" + "data=" + data + ", error=" + error + '}'; + } +} diff --git a/src/main/java/io/sui/models/objects/ObjectChange.java b/src/main/java/io/sui/models/objects/ObjectChange.java index bd0b3da..556b8ac 100644 --- a/src/main/java/io/sui/models/objects/ObjectChange.java +++ b/src/main/java/io/sui/models/objects/ObjectChange.java @@ -17,6 +17,7 @@ package io.sui.models.objects; +import java.math.BigInteger; import java.util.List; import java.util.Objects; @@ -53,7 +54,7 @@ public static class ObjectChangePublished extends ObjectChange { private String packageId; - private Long version; + private BigInteger version; private String digest; @@ -84,7 +85,7 @@ public void setPackageId(String packageId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -93,7 +94,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -202,7 +203,7 @@ public static class ObjectChangeTransferred extends ObjectChange { private String objectId; - private Long version; + private BigInteger version; private String digest; @@ -285,7 +286,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -294,7 +295,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -393,7 +394,9 @@ public static class ObjectChangeMutated extends ObjectChange { private String objectId; - private Long version; + private BigInteger version; + + private BigInteger previousVersion; private String digest; @@ -476,7 +479,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -485,7 +488,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -525,6 +528,24 @@ public void setType(ObjectChangeType type) { this.type = type; } + /** + * Gets previous version. + * + * @return the previous version + */ + public BigInteger getPreviousVersion() { + return previousVersion; + } + + /** + * Sets previous version. + * + * @param previousVersion the previous version + */ + public void setPreviousVersion(BigInteger previousVersion) { + this.previousVersion = previousVersion; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -539,13 +560,15 @@ public boolean equals(Object o) { && objectType.equals(that.objectType) && objectId.equals(that.objectId) && version.equals(that.version) + && previousVersion.equals(that.previousVersion) && digest.equals(that.digest) && type == that.type; } @Override public int hashCode() { - return Objects.hash(sender, owner, objectType, objectId, version, digest, type); + return Objects.hash( + sender, owner, objectType, objectId, version, previousVersion, digest, type); } @Override @@ -564,6 +587,8 @@ public String toString() { + '\'' + ", version=" + version + + ", previousVersion=" + + previousVersion + ", digest='" + digest + '\'' @@ -582,7 +607,7 @@ public static class ObjectChangeDeleted extends ObjectChange { private String objectId; - private Long version; + private BigInteger version; private ObjectChangeType type = ObjectChangeType.deleted; @@ -645,7 +670,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -654,7 +679,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -726,7 +751,7 @@ public static class ObjectChangeWrapped extends ObjectChange { private String objectId; - private Long version; + private BigInteger version; private ObjectChangeType type = ObjectChangeType.wrapped; @@ -789,7 +814,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -798,7 +823,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -872,7 +897,7 @@ public static class ObjectChangeCreated extends ObjectChange { private String objectId; - private Long version; + private BigInteger version; private String digest; @@ -955,7 +980,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -964,7 +989,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } diff --git a/src/main/java/io/sui/models/objects/ObjectStatus.java b/src/main/java/io/sui/models/objects/ObjectStatus.java index c91a259..3d2c480 100644 --- a/src/main/java/io/sui/models/objects/ObjectStatus.java +++ b/src/main/java/io/sui/models/objects/ObjectStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -26,7 +26,7 @@ public enum ObjectStatus { /** Exists object status. */ Exists, /** Not exists object status. */ - NotExists, + notExists, /** Deleted object status. */ Deleted, /** Object not exists object status. */ diff --git a/src/main/java/io/sui/models/objects/PaginatedCoins.java b/src/main/java/io/sui/models/objects/PaginatedCoins.java index ab3e5c3..ec4079b 100644 --- a/src/main/java/io/sui/models/objects/PaginatedCoins.java +++ b/src/main/java/io/sui/models/objects/PaginatedCoins.java @@ -17,8 +17,8 @@ package io.sui.models.objects; -import com.google.common.base.Objects; import java.util.List; +import java.util.Objects; /** * the paginated coins. @@ -32,6 +32,8 @@ public class PaginatedCoins { private String nextCursor; + private boolean hasNextPage; + public List getData() { return data; } @@ -48,25 +50,47 @@ public void getNextCursor(String nextCursor) { this.nextCursor = nextCursor; } + public void setNextCursor(String nextCursor) { + this.nextCursor = nextCursor; + } + + public boolean isHasNextPage() { + return hasNextPage; + } + + public void setHasNextPage(boolean hasNextPage) { + this.hasNextPage = hasNextPage; + } + @Override public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof PaginatedCoins)) { return false; } PaginatedCoins that = (PaginatedCoins) o; - return Objects.equal(data, that.data) && Objects.equal(nextCursor, that.nextCursor); + return hasNextPage == that.hasNextPage + && data.equals(that.data) + && nextCursor.equals(that.nextCursor); } @Override public int hashCode() { - return Objects.hashCode(data, nextCursor); + return Objects.hash(data, nextCursor, hasNextPage); } @Override public String toString() { - return "PaginatedCoins{" + "data=" + data + ", nextCursor=" + nextCursor + '}'; + return "PaginatedCoins{" + + "data=" + + data + + ", nextCursor='" + + nextCursor + + '\'' + + ", hasNextPage=" + + hasNextPage + + '}'; } } diff --git a/src/main/java/io/sui/models/objects/PaginatedObjectsResponse.java b/src/main/java/io/sui/models/objects/PaginatedObjectsResponse.java index 6c00a1e..9c4f2d2 100644 --- a/src/main/java/io/sui/models/objects/PaginatedObjectsResponse.java +++ b/src/main/java/io/sui/models/objects/PaginatedObjectsResponse.java @@ -30,7 +30,7 @@ public class PaginatedObjectsResponse { private List data; - private CheckpointedObjectId nextCursor; + private String nextCursor; private boolean hasNextPage; @@ -57,7 +57,7 @@ public void setData(List data) { * * @return the next cursor */ - public CheckpointedObjectId getNextCursor() { + public String getNextCursor() { return nextCursor; } @@ -66,7 +66,7 @@ public CheckpointedObjectId getNextCursor() { * * @param nextCursor the next cursor */ - public void setNextCursor(CheckpointedObjectId nextCursor) { + public void setNextCursor(String nextCursor) { this.nextCursor = nextCursor; } diff --git a/src/main/java/io/sui/models/objects/SuiObjectData.java b/src/main/java/io/sui/models/objects/SuiObjectData.java index d5a64b1..c9097f4 100644 --- a/src/main/java/io/sui/models/objects/SuiObjectData.java +++ b/src/main/java/io/sui/models/objects/SuiObjectData.java @@ -18,7 +18,7 @@ import io.sui.models.objects.ObjectResponse.ObjectResponseDetails; -import java.util.Map; +import java.math.BigInteger; import java.util.Objects; /** @@ -31,7 +31,7 @@ public class SuiObjectData implements ObjectResponseDetails { private String objectId; - private Long version; + private BigInteger version; private String digest; @@ -45,9 +45,9 @@ public class SuiObjectData implements ObjectResponseDetails { private String previousTransaction; - private Long storageRebate; + private BigInteger storageRebate; - private Map display; + private DisplayFieldsResponse display; /** * Gets object id. @@ -72,7 +72,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -81,7 +81,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -198,7 +198,7 @@ public void setPreviousTransaction(String previousTransaction) { * * @return the storage rebate */ - public Long getStorageRebate() { + public BigInteger getStorageRebate() { return storageRebate; } @@ -207,7 +207,7 @@ public Long getStorageRebate() { * * @param storageRebate the storage rebate */ - public void setStorageRebate(Long storageRebate) { + public void setStorageRebate(BigInteger storageRebate) { this.storageRebate = storageRebate; } @@ -216,7 +216,7 @@ public void setStorageRebate(Long storageRebate) { * * @return the display */ - public Map getDisplay() { + public DisplayFieldsResponse getDisplay() { return display; } @@ -225,7 +225,7 @@ public Map getDisplay() { * * @param display the display */ - public void setDisplay(Map display) { + public void setDisplay(DisplayFieldsResponse display) { this.display = display; } diff --git a/src/main/java/io/sui/models/objects/SuiObjectOwner.java b/src/main/java/io/sui/models/objects/SuiObjectOwner.java index 9863fad..32a2516 100644 --- a/src/main/java/io/sui/models/objects/SuiObjectOwner.java +++ b/src/main/java/io/sui/models/objects/SuiObjectOwner.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -17,6 +17,7 @@ package io.sui.models.objects; +import java.math.BigInteger; import java.util.Objects; /** @@ -134,14 +135,14 @@ class SharedOwner implements SuiObjectOwner { public static class Shared { @SuppressWarnings("checkstyle:MemberName") - private Long initial_shared_version; + private BigInteger initial_shared_version; /** * Gets initial shared version. * * @return the initial shared version */ - public Long getInitial_shared_version() { + public BigInteger getInitial_shared_version() { return initial_shared_version; } @@ -151,7 +152,7 @@ public Long getInitial_shared_version() { * @param initial_shared_version the initial shared version */ @SuppressWarnings("checkstyle:ParameterName") - public void setInitial_shared_version(Long initial_shared_version) { + public void setInitial_shared_version(BigInteger initial_shared_version) { this.initial_shared_version = initial_shared_version; } diff --git a/src/main/java/io/sui/models/objects/SuiObjectRef.java b/src/main/java/io/sui/models/objects/SuiObjectRef.java index 17030e3..8e9a202 100644 --- a/src/main/java/io/sui/models/objects/SuiObjectRef.java +++ b/src/main/java/io/sui/models/objects/SuiObjectRef.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -18,6 +18,7 @@ import io.sui.models.objects.ObjectResponse.ObjectResponseDetails; +import java.math.BigInteger; import java.util.Objects; /** @@ -32,7 +33,7 @@ public class SuiObjectRef implements ObjectResponseDetails { private String objectId; - private Long version; + private BigInteger version; /** * Gets digest. @@ -75,7 +76,7 @@ public void setObjectId(String objectId) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -84,7 +85,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } diff --git a/src/main/java/io/sui/models/objects/SuiObjectResponseError.java b/src/main/java/io/sui/models/objects/SuiObjectResponseError.java index 6e1375d..6464f8f 100644 --- a/src/main/java/io/sui/models/objects/SuiObjectResponseError.java +++ b/src/main/java/io/sui/models/objects/SuiObjectResponseError.java @@ -17,6 +17,7 @@ package io.sui.models.objects; +import java.math.BigInteger; import java.util.Objects; /** @@ -27,33 +28,17 @@ */ public class SuiObjectResponseError { - private String tag; + private String code; + + private String error; @SuppressWarnings("checkstyle:MemberName") private String object_id; - private Long version; + private BigInteger version; private String digest; - /** - * Gets tag. - * - * @return the tag - */ - public String getTag() { - return tag; - } - - /** - * Sets tag. - * - * @param tag the tag - */ - public void setTag(String tag) { - this.tag = tag; - } - /** * Gets object id. * @@ -78,7 +63,7 @@ public void setObject_id(String object_id) { * * @return the version */ - public Long getVersion() { + public BigInteger getVersion() { return version; } @@ -87,7 +72,7 @@ public Long getVersion() { * * @param version the version */ - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -109,6 +94,42 @@ public void setDigest(String digest) { this.digest = digest; } + /** + * Gets code. + * + * @return the code + */ + public String getCode() { + return code; + } + + /** + * Sets code. + * + * @param code the code + */ + public void setCode(String code) { + this.code = code; + } + + /** + * Gets error. + * + * @return the error + */ + public String getError() { + return error; + } + + /** + * Sets error. + * + * @param error the error + */ + public void setError(String error) { + this.error = error; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -118,7 +139,8 @@ public boolean equals(Object o) { return false; } SuiObjectResponseError that = (SuiObjectResponseError) o; - return tag.equals(that.tag) + return code.equals(that.code) + && error.equals(that.error) && object_id.equals(that.object_id) && version.equals(that.version) && digest.equals(that.digest); @@ -126,14 +148,17 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(tag, object_id, version, digest); + return Objects.hash(code, error, object_id, version, digest); } @Override public String toString() { return "SuiObjectResponseError{" - + "tag='" - + tag + + "code='" + + code + + '\'' + + ", error='" + + error + '\'' + ", object_id='" + object_id diff --git a/src/main/java/io/sui/models/objects/SuiRawData.java b/src/main/java/io/sui/models/objects/SuiRawData.java index 1975fae..ca715f6 100644 --- a/src/main/java/io/sui/models/objects/SuiRawData.java +++ b/src/main/java/io/sui/models/objects/SuiRawData.java @@ -17,6 +17,7 @@ package io.sui.models.objects; +import java.math.BigInteger; import java.util.Map; import java.util.Objects; @@ -37,7 +38,7 @@ public static class PackageObject extends SuiRawData { private Map moduleMap; - private Long version; + private BigInteger version; public String getId() { return id; @@ -63,11 +64,11 @@ public void setModuleMap(Map moduleMap) { this.moduleMap = moduleMap; } - public Long getVersion() { + public BigInteger getVersion() { return version; } - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } @@ -117,7 +118,7 @@ public static class MoveObject extends SuiRawData { private String type; - private Long version; + private BigInteger version; private String bcsBytes; @@ -185,11 +186,11 @@ public void setBcsBytes(String bcsBytes) { this.bcsBytes = bcsBytes; } - public Long getVersion() { + public BigInteger getVersion() { return version; } - public void setVersion(Long version) { + public void setVersion(BigInteger version) { this.version = version; } diff --git a/src/main/java/io/sui/models/transactions/GasCostSummary.java b/src/main/java/io/sui/models/transactions/GasCostSummary.java index fc6e48f..f8ba465 100644 --- a/src/main/java/io/sui/models/transactions/GasCostSummary.java +++ b/src/main/java/io/sui/models/transactions/GasCostSummary.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -17,6 +17,7 @@ package io.sui.models.transactions; +import java.math.BigInteger; import java.util.Objects; /** @@ -27,18 +28,20 @@ */ public class GasCostSummary { - private Long computationCost; + private BigInteger computationCost; - private Long storageCost; + private BigInteger storageCost; - private Long storageRebate; + private BigInteger storageRebate; + + private BigInteger nonRefundableStorageFee; /** * Gets computation cost. * * @return the computation cost */ - public Long getComputationCost() { + public BigInteger getComputationCost() { return computationCost; } @@ -47,7 +50,7 @@ public Long getComputationCost() { * * @param computationCost the computation cost */ - public void setComputationCost(Long computationCost) { + public void setComputationCost(BigInteger computationCost) { this.computationCost = computationCost; } @@ -56,7 +59,7 @@ public void setComputationCost(Long computationCost) { * * @return the storage cost */ - public Long getStorageCost() { + public BigInteger getStorageCost() { return storageCost; } @@ -65,7 +68,7 @@ public Long getStorageCost() { * * @param storageCost the storage cost */ - public void setStorageCost(Long storageCost) { + public void setStorageCost(BigInteger storageCost) { this.storageCost = storageCost; } @@ -74,7 +77,7 @@ public void setStorageCost(Long storageCost) { * * @return the storage rebate */ - public Long getStorageRebate() { + public BigInteger getStorageRebate() { return storageRebate; } @@ -83,27 +86,46 @@ public Long getStorageRebate() { * * @param storageRebate the storage rebate */ - public void setStorageRebate(Long storageRebate) { + public void setStorageRebate(BigInteger storageRebate) { this.storageRebate = storageRebate; } + /** + * Gets non refundable storage fee. + * + * @return the non refundable storage fee + */ + public BigInteger getNonRefundableStorageFee() { + return nonRefundableStorageFee; + } + + /** + * Sets non refundable storage fee. + * + * @param nonRefundableStorageFee the non refundable storage fee + */ + public void setNonRefundableStorageFee(BigInteger nonRefundableStorageFee) { + this.nonRefundableStorageFee = nonRefundableStorageFee; + } + @Override public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof GasCostSummary)) { return false; } GasCostSummary that = (GasCostSummary) o; return computationCost.equals(that.computationCost) && storageCost.equals(that.storageCost) - && storageRebate.equals(that.storageRebate); + && storageRebate.equals(that.storageRebate) + && nonRefundableStorageFee.equals(that.nonRefundableStorageFee); } @Override public int hashCode() { - return Objects.hash(computationCost, storageCost, storageRebate); + return Objects.hash(computationCost, storageCost, storageRebate, nonRefundableStorageFee); } @Override @@ -115,6 +137,8 @@ public String toString() { + storageCost + ", storageRebate=" + storageRebate + + ", nonRefundableStorageFee=" + + nonRefundableStorageFee + '}'; } } diff --git a/src/main/java/io/sui/models/transactions/GasData.java b/src/main/java/io/sui/models/transactions/GasData.java index 81c8ec2..c4fd294 100644 --- a/src/main/java/io/sui/models/transactions/GasData.java +++ b/src/main/java/io/sui/models/transactions/GasData.java @@ -18,6 +18,7 @@ import io.sui.models.objects.SuiObjectRef; +import java.math.BigInteger; import java.util.List; import java.util.Objects; @@ -28,9 +29,9 @@ public class GasData { private String owner; - private long price; + private BigInteger price; - private long budget; + private BigInteger budget; /** * Gets payment. @@ -73,7 +74,7 @@ public void setOwner(String owner) { * * @return the price */ - public long getPrice() { + public BigInteger getPrice() { return price; } @@ -82,7 +83,7 @@ public long getPrice() { * * @param price the price */ - public void setPrice(long price) { + public void setPrice(BigInteger price) { this.price = price; } @@ -91,7 +92,7 @@ public void setPrice(long price) { * * @return the budget */ - public long getBudget() { + public BigInteger getBudget() { return budget; } @@ -100,7 +101,7 @@ public long getBudget() { * * @param budget the budget */ - public void setBudget(long budget) { + public void setBudget(BigInteger budget) { this.budget = budget; } diff --git a/src/main/java/io/sui/models/transactions/TransactionBlockResponse.java b/src/main/java/io/sui/models/transactions/TransactionBlockResponse.java index c53b1fd..3ac2a11 100644 --- a/src/main/java/io/sui/models/transactions/TransactionBlockResponse.java +++ b/src/main/java/io/sui/models/transactions/TransactionBlockResponse.java @@ -19,6 +19,7 @@ import io.sui.models.events.SuiEvent; import io.sui.models.objects.ObjectChange; +import java.math.BigInteger; import java.util.List; import java.util.Objects; @@ -39,9 +40,9 @@ public class TransactionBlockResponse { private List events; @SuppressWarnings("checkstyle:MemberName") - private Long timestampMs; + private BigInteger timestampMs; - private Long checkpoint; + private BigInteger checkpoint; private boolean confirmedLocalExecution; @@ -126,7 +127,7 @@ public void setEvents(List events) { * * @return the timestamp ms */ - public Long getTimestampMs() { + public BigInteger getTimestampMs() { return timestampMs; } @@ -135,7 +136,7 @@ public Long getTimestampMs() { * * @param timestampMs the timestamp ms */ - public void setTimestampMs(Long timestampMs) { + public void setTimestampMs(BigInteger timestampMs) { this.timestampMs = timestampMs; } @@ -144,7 +145,7 @@ public void setTimestampMs(Long timestampMs) { * * @return the checkpoint */ - public Long getCheckpoint() { + public BigInteger getCheckpoint() { return checkpoint; } @@ -153,7 +154,7 @@ public Long getCheckpoint() { * * @param checkpoint the checkpoint */ - public void setCheckpoint(Long checkpoint) { + public void setCheckpoint(BigInteger checkpoint) { this.checkpoint = checkpoint; } diff --git a/src/main/java/io/sui/models/transactions/TransactionEffects.java b/src/main/java/io/sui/models/transactions/TransactionEffects.java index 79f6759..bc5cc23 100644 --- a/src/main/java/io/sui/models/transactions/TransactionEffects.java +++ b/src/main/java/io/sui/models/transactions/TransactionEffects.java @@ -19,6 +19,7 @@ import io.sui.models.objects.SuiObjectRef; import io.sui.models.objects.SuiOwnerObjectRef; +import java.math.BigInteger; import java.util.List; import java.util.Objects; @@ -34,7 +35,9 @@ public class TransactionEffects { private ExecutionStatus status; - private Long executedEpoch; + private BigInteger executedEpoch; + + private List modifiedAtVersions; private GasCostSummary gasUsed; @@ -102,7 +105,7 @@ public void setStatus(ExecutionStatus status) { * * @return the executed epoch */ - public Long getExecutedEpoch() { + public BigInteger getExecutedEpoch() { return executedEpoch; } @@ -111,7 +114,7 @@ public Long getExecutedEpoch() { * * @param executedEpoch the executed epoch */ - public void setExecutedEpoch(Long executedEpoch) { + public void setExecutedEpoch(BigInteger executedEpoch) { this.executedEpoch = executedEpoch; } @@ -332,6 +335,14 @@ public void setDependencies(List dependencies) { this.dependencies = dependencies; } + public List getModifiedAtVersions() { + return modifiedAtVersions; + } + + public void setModifiedAtVersions(List modifiedAtVersions) { + this.modifiedAtVersions = modifiedAtVersions; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -344,6 +355,7 @@ public boolean equals(Object o) { return messageVersion.equals(that.messageVersion) && status.equals(that.status) && executedEpoch.equals(that.executedEpoch) + && modifiedAtVersions.equals(that.modifiedAtVersions) && gasUsed.equals(that.gasUsed) && sharedObjects.equals(that.sharedObjects) && transactionDigest.equals(that.transactionDigest) @@ -364,6 +376,7 @@ public int hashCode() { messageVersion, status, executedEpoch, + modifiedAtVersions, gasUsed, sharedObjects, transactionDigest, @@ -388,6 +401,8 @@ public String toString() { + status + ", executedEpoch=" + executedEpoch + + ", modifiedAtVersions=" + + modifiedAtVersions + ", gasUsed=" + gasUsed + ", sharedObjects=" diff --git a/src/main/java/io/sui/models/transactions/TransactionEffectsModifiedAtVersions.java b/src/main/java/io/sui/models/transactions/TransactionEffectsModifiedAtVersions.java new file mode 100644 index 0000000..97381bc --- /dev/null +++ b/src/main/java/io/sui/models/transactions/TransactionEffectsModifiedAtVersions.java @@ -0,0 +1,98 @@ +/* + * Copyright 2023 281165273grape@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package io.sui.models.transactions; + + +import java.math.BigInteger; +import java.util.Objects; + +/** + * The type Transaction effects modified at versions. + * + * @author grapebaba + * @since 2023.04 + */ +public class TransactionEffectsModifiedAtVersions { + + private String objectId; + + private BigInteger sequenceNumber; + + /** + * Gets object id. + * + * @return the object id + */ + public String getObjectId() { + return objectId; + } + + /** + * Sets object id. + * + * @param objectId the object id + */ + public void setObjectId(String objectId) { + this.objectId = objectId; + } + + /** + * Gets sequence number. + * + * @return the sequence number + */ + public BigInteger getSequenceNumber() { + return sequenceNumber; + } + + /** + * Sets sequence number. + * + * @param sequenceNumber the sequence number + */ + public void setSequenceNumber(BigInteger sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TransactionEffectsModifiedAtVersions)) { + return false; + } + TransactionEffectsModifiedAtVersions that = (TransactionEffectsModifiedAtVersions) o; + return objectId.equals(that.objectId) && sequenceNumber.equals(that.sequenceNumber); + } + + @Override + public int hashCode() { + return Objects.hash(objectId, sequenceNumber); + } + + @Override + public String toString() { + return "TransactionEffectsModifiedAtVersions{" + + "objectId='" + + objectId + + '\'' + + ", sequenceNumber=" + + sequenceNumber + + '}'; + } +} diff --git a/src/test/java/io/sui/clients/ExecutionClientImplTest.java b/src/test/java/io/sui/clients/ExecutionClientImplTest.java index b06b3d3..4cd8c81 100644 --- a/src/test/java/io/sui/clients/ExecutionClientImplTest.java +++ b/src/test/java/io/sui/clients/ExecutionClientImplTest.java @@ -137,7 +137,7 @@ void dryRunTransaction() throws ExecutionException, InterruptedException { System.out.println(res.get()); assertEquals(success, res.get().getStatus().getStatus()); - assertEquals(793L, res.get().getGasUsed().getComputationCost()); + assertEquals(793L, res.get().getGasUsed().getComputationCost().longValue()); assertEquals( "uZnJ/TEjGRaJ29KC5QY+mz7KN/EV4cdeJVLc64KJtZ4=", res.get().getMutated().get(0).getReference().getDigest()); diff --git a/src/test/java/io/sui/clients/NewQueryClientImplTests.java b/src/test/java/io/sui/clients/NewQueryClientImplTests.java deleted file mode 100644 index 2347d9d..0000000 --- a/src/test/java/io/sui/clients/NewQueryClientImplTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2023 281165273grape@gmail.com - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package io.sui.clients; - - -import io.sui.jsonrpc.GsonJsonHandler; -import io.sui.jsonrpc.JsonHandler; -import io.sui.jsonrpc.JsonRpcClientProvider; -import io.sui.jsonrpc.OkHttpJsonRpcClientProvider; -import org.junit.jupiter.api.BeforeAll; - -/** Created by IntelliJ IDEA. Author: kaichen Date: 2023/3/7 Time: 20:31 */ -public class NewQueryClientImplTests { - - private static final String BASE_URL = "https://fullnode.devnet.sui.io"; - // private static final String BASE_URL = "http://localhost:9000"; - - private static final JsonHandler jsonHandler = new GsonJsonHandler(); - - private static QueryClient client; - - /** Before all. */ - @BeforeAll - static void beforeAll() { - JsonRpcClientProvider jsonRpcClientProvider = - new OkHttpJsonRpcClientProvider(BASE_URL, jsonHandler); - client = new QueryClientImpl(jsonRpcClientProvider); - } -}