Skip to content

Commit

Permalink
fix: create oracle (#2565)
Browse files Browse the repository at this point in the history
* fix: create oracle

* fix: change decimal value to u256

* fix: change admin_cap to oracle admin cap

* merge main and fix doc

* fix: compare

---------

Co-authored-by: mx819812523 <mx819812523@gamil.com>
  • Loading branch information
mx819812523 and mx819812523 authored Sep 3, 2024
1 parent c1fa227 commit f517ad4
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 22 deletions.
Binary file modified frameworks/framework-release/released/8/0x2/package.rpd
Binary file not shown.
Binary file modified frameworks/framework-release/released/8/0x3/package.rpd
Binary file not shown.
Binary file modified frameworks/framework-release/released/8/stdlib
Binary file not shown.
4 changes: 2 additions & 2 deletions frameworks/moveos-stdlib/doc/decimal_value.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_new">new</a>(value: u64, decimal: u8): <a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>
<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_new">new</a>(value: <a href="">u256</a>, decimal: u8): <a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>
</code></pre>


Expand All @@ -43,7 +43,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_value">value</a>(self: &<a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>): u64
<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_value">value</a>(self: &<a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>): <a href="">u256</a>
</code></pre>


Expand Down
4 changes: 2 additions & 2 deletions frameworks/moveos-stdlib/sources/compare.move
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ module moveos_std::compare {
return LESS_THAN
}
} else if (t == type_name::get<DecimalValue>()) {
let a_value = bcs::peel_u64(&mut a);
let a_value = bcs::peel_u256(&mut a);
let a_decimal = bcs::peel_u8(&mut a);
let b_value = bcs::peel_u64(&mut b);
let b_value = bcs::peel_u256(&mut b);
let b_decimal = bcs::peel_u8(&mut b);
// Normalise the decimal values
let a = (a_value as u256) * u256::pow(10, b_decimal);
Expand Down
6 changes: 3 additions & 3 deletions frameworks/moveos-stdlib/sources/decimal_value.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

module moveos_std::decimal_value {
struct DecimalValue has store, drop, copy {
value: u64,
value: u256,
decimal: u8,
}

public fun new(value: u64, decimal: u8): DecimalValue {
public fun new(value: u256, decimal: u8): DecimalValue {
DecimalValue { value, decimal }
}

public fun value(self: &DecimalValue): u64 {
public fun value(self: &DecimalValue): u256 {
self.value
}

Expand Down
29 changes: 21 additions & 8 deletions frameworks/rooch-framework/doc/oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

- [Resource `TablePlaceholder`](#0x3_oracle_TablePlaceholder)
- [Resource `SimpleOracle`](#0x3_oracle_SimpleOracle)
- [Resource `AdminCap`](#0x3_oracle_AdminCap)
- [Resource `OracleAdminCap`](#0x3_oracle_OracleAdminCap)
- [Struct `StoredData`](#0x3_oracle_StoredData)
- [Constants](#@Constants_0)
- [Function `get_historical_data`](#0x3_oracle_get_historical_data)
- [Function `get_latest_data`](#0x3_oracle_get_latest_data)
- [Function `create_entry`](#0x3_oracle_create_entry)
- [Function `create`](#0x3_oracle_create)
- [Function `submit_data`](#0x3_oracle_submit_data)
- [Function `archive_data`](#0x3_oracle_archive_data)
Expand Down Expand Up @@ -50,13 +51,13 @@



<a name="0x3_oracle_AdminCap"></a>
<a name="0x3_oracle_OracleAdminCap"></a>

## Resource `AdminCap`
## Resource `OracleAdminCap`



<pre><code><b>struct</b> <a href="oracle.md#0x3_oracle_AdminCap">AdminCap</a> <b>has</b> store, key
<pre><code><b>struct</b> <a href="oracle.md#0x3_oracle_OracleAdminCap">OracleAdminCap</a> <b>has</b> store, key
</code></pre>


Expand Down Expand Up @@ -117,14 +118,26 @@



<a name="0x3_oracle_create_entry"></a>

## Function `create_entry`

Create a new shared SimpleOracle object for publishing data.


<pre><code><b>public</b> entry <b>fun</b> <a href="oracle.md#0x3_oracle_create_entry">create_entry</a>(name: <a href="_String">string::String</a>, url: <a href="_String">string::String</a>, description: <a href="_String">string::String</a>)
</code></pre>



<a name="0x3_oracle_create"></a>

## Function `create`

Create a new shared SimpleOracle object for publishing data.
Create a new SimpleOracle object for publishing data.


<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_create">create</a>(name: <a href="_String">string::String</a>, url: <a href="_String">string::String</a>, description: <a href="_String">string::String</a>): <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_AdminCap">oracle::AdminCap</a>&gt;
<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_create">create</a>(name: <a href="_String">string::String</a>, url: <a href="_String">string::String</a>, description: <a href="_String">string::String</a>): (<a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
</code></pre>


Expand All @@ -135,7 +148,7 @@ Create a new shared SimpleOracle object for publishing data.



<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_submit_data">submit_data</a>&lt;T: <b>copy</b>, drop, store&gt;(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, value: T, identifier: <a href="_String">string::String</a>, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_AdminCap">oracle::AdminCap</a>&gt;)
<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_submit_data">submit_data</a>&lt;T: <b>copy</b>, drop, store&gt;(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, value: T, identifier: <a href="_String">string::String</a>, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
</code></pre>


Expand All @@ -146,5 +159,5 @@ Create a new shared SimpleOracle object for publishing data.



<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_archive_data">archive_data</a>&lt;K: <b>copy</b>, drop, store, V: <b>copy</b>, drop, store&gt;(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, archival_key: K, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_AdminCap">oracle::AdminCap</a>&gt;)
<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_archive_data">archive_data</a>&lt;K: <b>copy</b>, drop, store, V: <b>copy</b>, drop, store&gt;(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, archival_key: K, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
</code></pre>
33 changes: 26 additions & 7 deletions frameworks/rooch-framework/sources/oracle/oracle.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module rooch_framework::oracle {
url: String,
}

struct AdminCap has key, store {
struct OracleAdminCap has key, store {
oracle_id: ObjectID
}

Expand Down Expand Up @@ -72,21 +72,40 @@ module rooch_framework::oracle {
}

/// Create a new shared SimpleOracle object for publishing data.
public fun create(name: String, url: String, description: String): Object<AdminCap> {
let oracle = object::new(SimpleOracle { id: object::new(TablePlaceholder{_placeholder: false}), address: sender(), name, description, url });
public entry fun create_entry(name: String, url: String, description: String) {
let oracle = object::new(
SimpleOracle {
id: object::new(TablePlaceholder { _placeholder: false }), address: sender(
), name, description, url
}
);
let oracle_id = object::id(&oracle);
object::to_shared(oracle);
object::new(AdminCap{
object::transfer(object::new(OracleAdminCap {
oracle_id
}), sender())
}

/// Create a new SimpleOracle object for publishing data.
public fun create(name: String, url: String, description: String): (Object<SimpleOracle>, Object<OracleAdminCap>) {
let oracle = object::new(
SimpleOracle {
id: object::new(TablePlaceholder { _placeholder: false }), address: sender(
), name, description, url
}
);
let oracle_id = object::id(&oracle);
(oracle, object::new(OracleAdminCap {
oracle_id
})
}))
}

public fun submit_data<T: store + copy + drop>(
oracle_obj: &mut Object<SimpleOracle>,
ticker: String,
value: T,
identifier: String,
admin_obj: &mut Object<AdminCap>,
admin_obj: &mut Object<OracleAdminCap>,
) {
let oracle_id = object::id(oracle_obj);
let admin_id = object::borrow(admin_obj).oracle_id;
Expand All @@ -113,7 +132,7 @@ module rooch_framework::oracle {
oracle_obj: &mut Object<SimpleOracle>,
ticker: String,
archival_key: K,
admin_obj: &mut Object<AdminCap>,
admin_obj: &mut Object<OracleAdminCap>,
) {
let oracle_id = object::id(oracle_obj);
let admin_id = object::borrow(admin_obj).oracle_id;
Expand Down

0 comments on commit f517ad4

Please sign in to comment.