Skip to content

Commit

Permalink
solution: rpc for contracts rent projection
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Jun 29, 2020
1 parent df8609a commit 1005e67
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
15 changes: 14 additions & 1 deletion docs/ref-01-api-commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Contracts
- <<contractsCall>>
- <<contractsGetStorage>>
- <<contractsRentProjection>>
* State
- <<stateMetadata>>
- <<stateGetStorage>>
Expand Down Expand Up @@ -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`)
Expand All @@ -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`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public RpcCall<ContractExecResultJson> contractsCall(ContractCallRequestJson req
*
* @param address contract address
* @param key key
* @return value for the key, or null
* @return comman
*/
public RpcCall<ByteData> contractsGetStorage(Address address, Hash256 key) {
return RpcCall.create(ByteData.class, "contracts_getStorage", address, key);
Expand All @@ -159,7 +159,7 @@ public RpcCall<ByteData> 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<ByteData> contractsGetStorage(Address address, Hash256 key, Hash256 at) {
if (at == null) {
Expand All @@ -168,4 +168,26 @@ public RpcCall<ByteData> contractsGetStorage(Address address, Hash256 key, Hash2
return RpcCall.create(ByteData.class, "contracts_getStorage", address, key, at);
}

/**
*
* @param address contract address
* @return command
*/
public RpcCall<Long> contractsRentProjection(Address address) {
return RpcCall.create(Long.class, "contracts_rentProjection", address);
}

/**
*
* @param address contract address
* @param at block hash
* @return command
*/
public RpcCall<Long> contractsRentProjection(Address address, Hash256 at) {
if (at == null) {
return contractsRentProjection(address);
}
return RpcCall.create(Long.class, "contracts_rentProjection", address, at);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 1005e67

Please sign in to comment.