Skip to content

Commit e56053f

Browse files
AtlasoinHenryQW
andauthored
feat: update initialization (#5)
* update install method * feat: update initialization * chore: admin -> owner --------- Co-authored-by: Henry <[email protected]>
1 parent 586f9bc commit e56053f

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

content/guide/openchain/ovm/specification.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Example: ovm-cal-pi
6161

6262
Version of the specification schema.
6363

64-
Example: v1.0.0
64+
Currently: 1.0.0
6565

6666
### Description
6767

content/guide/openchain/ovm/task.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ You should use foundry to [create a new project](https://book.getfoundry.sh/proj
3131
forge install https://github.com/webisopen/ovm-contracts
3232
```
3333

34-
3534
2. Otherwise you can use NPM to install the dependencies, there are two packages required:
3635

37-
3836
```bash
3937
npm i @webisopen/ovm-contracts @openzeppelin/contracts
4038
```
@@ -51,21 +49,24 @@ You may refer to the [OVM Cal PI](https://github.com/webisopen/ovm-cal-pi) repos
5149

5250
#### Initialization
5351

54-
The constructor initializes the smart contract with the specification of the task to be executed.
52+
This contract inherits from `OVMClient` and `OwnableUpgradeable`.
53+
In the ``initialize`` method, it initializes the smart contract with the specification of the task to be executed.
5554
For more details, refer to the [OVM Contract Specification](./specification).
5655

57-
Additionally, `admin` address is also defined in the constructor for collecting royalty fees.
56+
Additionally, `owner` address is defined to collect royalty fees escrowed in the contract.
5857

5958
```solidity
60-
constructor(
61-
address OVMTaskAddress,
62-
address admin
63-
) OVMClient(OVMTaskAddress, admin) {
59+
contract Pi is OVMClient, OwnableUpgradeable {
60+
// ...
61+
function initialize(address owner) external initializer {
62+
__Ownable_init(owner);
63+
64+
// set specification
6465
Specification memory spec;
6566
spec.name = "ovm-cal-pi";
6667
spec.version = "1.0.0";
6768
spec.description = "Calculate PI";
68-
spec.repository = "https://github.com/webisopen/ovm-cal-pi";
69+
spec.repository = "https://github.com/webisopen/ovm-pi";
6970
spec.repoTag = "9231c80a6cba45c8ff9a1d3ba19e8596407e8850";
7071
spec.license = "WTFPL";
7172
spec.requirement = Requirement({
@@ -76,14 +77,16 @@ Additionally, `admin` address is also defined in the constructor for collecting
7677
gpu: 0,
7778
gpuModel: GPUModel.T4
7879
});
79-
spec
80-
.apiABIs = '[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
80+
spec.apiABIs =
81+
'[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
8182
spec.royalty = 5;
8283
spec.execMode = ExecMode.JIT;
83-
spec.arch = Arch.ARM64;
84+
spec.arch = Arch.AMD64;
8485
8586
_updateSpecification(spec);
8687
}
88+
// ...
89+
}
8790
```
8891

8992
#### Send Request
@@ -141,6 +144,15 @@ The interface `function setResponse(bytes32 requestId, bytes calldata data)` mus
141144

142145
Similarly, you need to decode the response here.
143146

147+
#### Collect Royalty
148+
149+
Royalty fees are escrowed in the contract, this function enables the owner to withdraw the fees.
150+
```solidity
151+
function withdraw() external onlyOwner {
152+
payable(owner()).transfer(address(this).balance);
153+
}
154+
```
155+
144156
## Conclusion
145157

146158
In this guide, we demonstrated how to publish an OVM task by building a smart contract that specifies the computation to be executed, the environment in which it should run, and the requirements for the execution.

content/guide/openchain/ovm/tutorial/pi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Common features are implemented in the `OVMClient` contract, which can be import
148148
contract Pi is OVMClient {
149149
mapping(bytes32 requestId => string result) internal _results;
150150
151-
constructor(address ovmTaskAddress, address admin) OVMClient(ovmTaskAddress, admin) {
151+
constructor(address ovmTaskAddress, address owner) OVMClient(ovmTaskAddress, owner) {
152152
Requirement memory requirement =
153153
Requirement({ram: "128mb", disk: "100mb", timeout: 1000, cpu: 1, gpu: 0, gpuModel: GPUModel.T4});
154154

0 commit comments

Comments
 (0)