Andromeda
Search
⌃K

Primitive

Introduction

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

InstantiateMsg

Rust
pub struct InstantiateMsg {}

ExecuteMsg

SetValue

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 nameis 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
name
Option<String>
Optional name for the data.
value
Primitive
The value of the data.

Primitive

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)
}

DeleteValue

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>
Optional key for the data to delete. If not specified, the default key will be used.

AndrReceive

The rest of the executes can be found in the AndrReceive section.

QueryMsg

AndrQuery

pub enum QueryMsg {
AndrQuery(AndromedaQuery),
}
If the AndromedaQuery is of type Get , the contract will query the value of the specified key (data). If no data is supplied in the Get, then the contract will query the default key value.
fn handle_andromeda_query(
deps: Deps,
env: Env,
msg: AndromedaQuery,
) -> Result<Binary, ContractError> {
match msg {
AndromedaQuery::Get(data) => match data {
// Treat no binary as request to get value with default key.
None => encode_binary(&query_value(deps, None)?),
Some(_) => {
let name: String = parse_message(&data)?;
encode_binary(&query_value(deps, Some(name))?)
}
},
_ => ADOContract::default().query(deps, env, msg, query),
}
}
Check AndrQuery for the rest of the default queries.