Comment on page
Primitive
The Primitive ADO is a smart contract that is used to store data for another contract. It is a simple contract that allows us to store key/value pairs to be reference when needed.
The primitive contract is used in situations where data will most likely be used several times saving us the cost of redefining it every single time. Instead, the primitive contract address can be added to the ADOs that utilize it (Found in the
InstantiationMsg
of the ADO). Ado_type: primitive
Rust
JSON
pub struct InstantiateMsg {
pub restriction:PrimitiveRestriction,
pub kernel_address: String,
pub owner: Option<String>
}
{
"restriction":"public",
"kernel_address":"andr1..."
}
Name | Type | Description |
---|---|---|
restriction | Specifies who has access to add/delete data into the primitive ADO. | |
kernel_address | String | Contract address of the kernel contract to be used for AMP messaging. Kernel contract address can be found in our deployed contracts. |
owner | Option<String> | Optional address to specify as the owner of the ADO being created. Defaults to the sender if not specified. |
An enum defining the different types of restrictions that can be set.
pub enum PrimitiveRestriction {
Private,
Public,
Restricted,
}
- Private: Only accessible by the contract owner/operator of the ADO.
- Public: Accessible by anyone.
- Restricted: Only accessible to the key owner (The address that first set the key).
Sets a value for the named key. When we need to extract the value that has been saved we would use the key (name).
If
name
is not specified the default key ("default") will be used.If
SetValue
uses a name
that is already in use, the old value
is overwritten by the latest value.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg{
SetValue {
key: Option<String>,
value: Primitive,
}
}
{
"set_value": {
"key": "rate_name",
"value": {
"coin": {
"denom": "uandr",
"amount": "100"
}
}
}
}
Name | Type | Description |
---|---|---|
key | Option<String> | The key for the data. The default key "default" will be used if it is not specified. |
value | The value of the data. |
An enum to specify the type of data you are saving.
pub enum Primitive {
Uint128(Uint128),
Decimal(Decimal),
Coin(Coin),
String(String),
Bool(bool),
Vec(Vec<Primitive>),
Binary(Binary),
Object(Map<String, Primitive>),
}
Deletes the data attached to the specified
name
.If
name
is not specified the default key ("default") will be used.Only available to the contract owner/operator
Rust
JSON
pub enum ExecuteMsg{
DeleteValue {
key: Option<String>,
}
}
{
"delete_value":{
"key":"rate_name"
}
}
Name | Type | Description |
---|---|---|
key | Option<String> | Thel key for the data to delete. If not specified, the default key "default" will be used. |
Changes the restriction set on the primitive.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg {
UpdateRestriction {
restriction: PrimitiveRestriction,
},
}
{
"update_restriction":{
"restriction":"private"
}
}
Name | Type | Description |
---|---|---|
restriction | The new restriction type to use for the primitve ADO. |
Gets the value asociated to the specified key.
Rust
JSON
pub enum QueryMsg {
#[returns(GetValueResponse)]
GetValue { key: Option<String> },
}
{
"get_value":{
"key":"funds"
}
}
Name | Type | Description |
---|---|---|
key | Option<String> | The key to get the value for. The default key is used if it is not specified. |
Rust
JSON
pub struct GetValueResponse {
pub key: String,
pub value: Primitive,
}
{
"key":"funds",
"value": {
"coin": {
"denom": "uandr",
"amount": "100"
}
}
}
Name | Type | Description |
---|---|---|
key | String | The key you are getting the value for. |
value | The value for the specified key. |
Gets all the keys that are currently saved in the primitive ADO.
Rust
JSON
pub enum QueryMsg {
#[returns(Vec<String>)]
AllKeys {},
}
{
"all_keys":{}
}
Returns a Vec<String> containing all the available keys.
Gets all the keys that belong to the specified owner address.
Rust
JSON
pub enum QueryMsg {
#[returns(Vec<String>)]
OwnerKeys { owner: AndrAddr },
}
{
"owner_keys":{
"owner":"andr1..."
}
}
Name | Type | Description |
---|---|---|
owner | The address to get the keys for. |
Returns a Vec<String> containing all the keys belonging to the specified
owner
.Last modified 24d ago