diff --git a/docs/ref-01-api-commands.adoc b/docs/ref-01-api-commands.adoc index 9cc9def..fec9f1f 100644 --- a/docs/ref-01-api-commands.adoc +++ b/docs/ref-01-api-commands.adoc @@ -11,6 +11,7 @@ * Contracts - <> - <> +- <> * State - <> - <> @@ -80,6 +81,8 @@ Java Object:: `RuntimeVersionJson` [#contractsCall] === Contracts Call (`contracts_call`) +Executes a call to a contract + Shortcut:: `{shortcut-base}.contractsCall(call, at)` Command:: `contracts_call` Parameters:: `call` - requests data `ContractCallRequestJson`, `at` - (optional) block reference (`Hash256`) @@ -88,13 +91,23 @@ Java Object:: `ContractExecResultJson` [#contractsGetStorage] === Contracts Get Storage (`contracts_getStorage`) -Get state from a Storage. +Get value under a specified storage key in a contract. Shortcut:: `{shortcut-base}.contractsGetStorage(address, key, at)` Command:: `contracts_getStorage` Parameters:: `address` - contract address (`Address`), `key` - key (`Has256`), `at` - (optional) block reference (`Hash256`) Java Object:: `ByteData` +[#contractsRentProjection] +=== Contracts Rent Projection (`contracts_rentProjection`) + +Get projected time a given contract will be able to sustain paying its rent + +Shortcut:: `{shortcut-base}.contractsRentProjection(address, at)` +Command:: `contracts_getStorage` +Parameters:: `address` - contract address (`Address`), `at` - (optional) block reference (`Hash256`) +Java Object:: `Long` + [#stateMetadata] === State Runtime Metadata (`state_getMetadata`) diff --git a/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java b/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java index 555dcfc..2ed06fe 100644 --- a/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java +++ b/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java @@ -148,7 +148,7 @@ public RpcCall contractsCall(ContractCallRequestJson req * * @param address contract address * @param key key - * @return value for the key, or null + * @return comman */ public RpcCall contractsGetStorage(Address address, Hash256 key) { return RpcCall.create(ByteData.class, "contracts_getStorage", address, key); @@ -159,7 +159,7 @@ public RpcCall contractsGetStorage(Address address, Hash256 key) { * @param address contract address * @param key key * @param at block hash - * @return value for the key, or null + * @return command */ public RpcCall contractsGetStorage(Address address, Hash256 key, Hash256 at) { if (at == null) { @@ -168,4 +168,26 @@ public RpcCall contractsGetStorage(Address address, Hash256 key, Hash2 return RpcCall.create(ByteData.class, "contracts_getStorage", address, key, at); } + /** + * + * @param address contract address + * @return command + */ + public RpcCall contractsRentProjection(Address address) { + return RpcCall.create(Long.class, "contracts_rentProjection", address); + } + + /** + * + * @param address contract address + * @param at block hash + * @return command + */ + public RpcCall contractsRentProjection(Address address, Hash256 at) { + if (at == null) { + return contractsRentProjection(address); + } + return RpcCall.create(Long.class, "contracts_rentProjection", address, at); + } + } diff --git a/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy b/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy index c0330b4..6b6ed61 100644 --- a/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy +++ b/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy @@ -214,4 +214,32 @@ class StandardCommandsSpec extends Specification { ] act.getResultType(typeFactory).getRawClass() == ByteData.class } + + def "Contracts Rent Projection"() { + when: + def act = StandardCommands.getInstance().contractsRentProjection(Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy")) + then: + act.method == "contracts_rentProjection" + act.params.toList() == [Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy")] + act.getResultType(typeFactory).getRawClass() == Long.class + + when: + act = StandardCommands.getInstance().contractsRentProjection(Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy"), null) + then: + act.method == "contracts_rentProjection" + act.params.toList() == [Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy")] + act.getResultType(typeFactory).getRawClass() == Long.class + + when: + act = StandardCommands.getInstance().contractsRentProjection( + Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy"), + Hash256.from("0x5c51037f13c637196779564726176d10f000b4fb443248278180c1adcb814d23")) + then: + act.method == "contracts_rentProjection" + act.params.toList() == [ + Address.from("FqZJib4Kz759A1VFd2cXX4paQB42w7Uamsyhi4z3kGgCkQy"), + Hash256.from("0x5c51037f13c637196779564726176d10f000b4fb443248278180c1adcb814d23") + ] + act.getResultType(typeFactory).getRawClass() == Long.class + } }