Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token contract -- (tested) #12

Closed
wants to merge 21 commits into from
Closed

Token contract -- (tested) #12

wants to merge 21 commits into from

Conversation

njeans
Copy link
Collaborator

@njeans njeans commented Jun 18, 2023

  • cargo test
  • cargo build --target wasm32-unknown-unknown
  • deployment to a local devnet

@njeans njeans changed the title Token contract -- (untested) Token contract -- (tested) Jun 18, 2023
@sbellem
Copy link
Contributor

sbellem commented Jun 19, 2023

We need to figure out why cargo build --target wasm32-unknown-unknown fails.

The main issue is with the query() function. The entry_point macro expects 3 parameters whereas 4 are passed.

Just for troubleshooting's sake, the patch shown below builds without error, but the check a.address == info.sender in get_balance() is removed, hence it's not a solution but helps to pinpoint where the problem is. As far as I understand get_balance() is the only function that depends on MessageInfo (process_request() does not).

diff --git a/src/contract.rs b/src/contract.rs
index 1e6fc95..74596f1 100644
--- a/src/contract.rs
+++ b/src/contract.rs
@@ -309,7 +309,8 @@ fn try_write_checkpoint(
 // ---------------------------------------- QUERIES --------------------------------------
 
 #[entry_point]
-pub fn query(deps: Deps, env: Env, info: MessageInfo, msg: QueryMsg) -> StdResult<Binary> {
+//pub fn query(deps: Deps, env: Env, info: MessageInfo, msg: QueryMsg) -> StdResult<Binary> {
+pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
     match msg {
         QueryMsg::GetState {
         } => qet_state(deps, env),
@@ -325,9 +326,11 @@ pub fn query(deps: Deps, env: Env, info: MessageInfo, msg: QueryMsg) -> StdResul
         } => get_checkpoint(deps, env),
         QueryMsg::ProcessNext {
             cipher
-        } => process_request(deps, env, info, cipher),
+        //} => process_request(deps, env, info, cipher),
+        } => process_request(deps, env, cipher),
         QueryMsg::GetBalance {
-        } => get_balance(deps, env, info)
+        //} => get_balance(deps, env, info)
+        } => get_balance(deps, env)
     }
 }
 
@@ -445,7 +448,7 @@ fn get_checkpoint(
 fn get_balance(
     deps: Deps,
     _env: Env,
-    info: MessageInfo
+    //info: MessageInfo
 ) -> StdResult<Binary> {
 
     let checkpoint = CheckPoint::load(deps.storage)?;
@@ -453,7 +456,8 @@ fn get_balance(
     let mut res = Uint128::zero();
     for i in 0..checkpoint.checkpoint.len() {
         let a = checkpoint.checkpoint.get(i).unwrap();
-        let b: bool = a.address == info.sender;
+        //let b: bool = a.address == info.sender;
+        let b: bool = true;
         let b_int = bool_to_uint128(b);
         res = res.checked_add(a.balance.checked_mul(b_int).unwrap()).unwrap();
     }
@@ -464,7 +468,7 @@ fn get_balance(
 fn process_request(
     deps: Deps,
     env: Env,
-    info: MessageInfo,
+    //info: MessageInfo,
     cipher: Binary
 )-> StdResult<Binary> {
     let mut checkpoint: CheckPoint = CheckPoint::decrypt_checkpoint(deps.storage, cipher).unwrap();

@sbellem
Copy link
Contributor

sbellem commented Jun 19, 2023

Wonder if this could work ...

diff --git a/src/contract.rs b/src/contract.rs
index 1e6fc95..30f5211 100644
--- a/src/contract.rs
+++ b/src/contract.rs
@@ -309,7 +309,7 @@ fn try_write_checkpoint(
 // ---------------------------------------- QUERIES --------------------------------------
 
 #[entry_point]
-pub fn query(deps: Deps, env: Env, info: MessageInfo, msg: QueryMsg) -> StdResult<Binary> {
+pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
     match msg {
         QueryMsg::GetState {
         } => qet_state(deps, env),
@@ -325,9 +325,10 @@ pub fn query(deps: Deps, env: Env, info: MessageInfo, msg: QueryMsg) -> StdResul
         } => get_checkpoint(deps, env),
         QueryMsg::ProcessNext {
             cipher
-        } => process_request(deps, env, info, cipher),
+        } => process_request(deps, env, cipher),
         QueryMsg::GetBalance {
-        } => get_balance(deps, env, info)
+            address
+        } => get_balance(deps, env, address)
     }
 }
 
@@ -445,7 +446,8 @@ fn get_checkpoint(
 fn get_balance(
     deps: Deps,
     _env: Env,
-    info: MessageInfo
+    // FIXME ?
+    address: Addr
 ) -> StdResult<Binary> {
 
     let checkpoint = CheckPoint::load(deps.storage)?;
@@ -453,7 +455,8 @@ fn get_balance(
     let mut res = Uint128::zero();
     for i in 0..checkpoint.checkpoint.len() {
         let a = checkpoint.checkpoint.get(i).unwrap();
-        let b: bool = a.address == info.sender;
+        // FIXME ?
+        let b: bool = a.address == address;
         let b_int = bool_to_uint128(b);
         res = res.checked_add(a.balance.checked_mul(b_int).unwrap()).unwrap();
     }
@@ -464,7 +467,6 @@ fn get_balance(
 fn process_request(
     deps: Deps,
     env: Env,
-    info: MessageInfo,
     cipher: Binary
 )-> StdResult<Binary> {
     let mut checkpoint: CheckPoint = CheckPoint::decrypt_checkpoint(deps.storage, cipher).unwrap();
diff --git a/src/msg.rs b/src/msg.rs
index f0872dc..5982cd7 100644
--- a/src/msg.rs
+++ b/src/msg.rs
@@ -48,7 +48,9 @@ pub enum QueryMsg {
         old_mac: Binary,
     },
 
-    GetBalance{},
+    GetBalance{
+        address: Addr
+    },
 
     GetRequest {
         seqno: Uint128

@sbellem
Copy link
Contributor

sbellem commented Jun 19, 2023

This might work: 32dbeb9

Tests pass, and build in docker worked on my laptop.

image

@sbellem
Copy link
Contributor

sbellem commented Jun 19, 2023

@njeans check it out! Let me know if that makes sense. 32dbeb9

@sbellem
Copy link
Contributor

sbellem commented Jun 19, 2023

Deploying the contract does not work ... stuck on the storing step. secretcli query compute list-code does not output anything.

047BpdqfBRF1+LapPcZeeSMwNB0uyEWi1s2Sw6l6Jgq9exoUsdlSGK62w0k6VgUTjSY54hKK1vvxM6g1WRCTRsXowQrAjPsp4pfrwn++6cKv0BU9r7r2xcyE4cPvb5oMWkspW2UDuys2H52krOedzjOcvosxf9fEGWlI4nKWqCGS+pLTzmFPagOsiWRhOqegyS+2Z5M78NeLA+xrqcaV4Cy8Y+Jpsy+OMtV3En7kUHpi2iIe7po8JQ8wcClpxrgh+JYt0mOHu6YPAeRYjMkNvcX29g+6uvhqjG1oVApZHly3E5lPgR69KygwWmAO9ZD9e5qZCeaaz2BggBubQmUeUMcH47kYfWqiCNkIIRcvNJ/8036DSzGVJtJK5eyOwBdUQmNAQjK9w+annJ8sgmcyYbVSeWpSIzZ5r3w8U8c6kYZvGayRgvXWbdclO6w1oYA5YKx1+vJggENlCvl/KsV/AZIVgWbBgAcA","source":"","builder":""}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[{"denom":"uscrt","amount":"1250000"}],"gas_limit":"5000000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
{"height":"0","txhash":"FC0D5AE1EB1CB416E13452032970AE1BA24D1CA4EB8BB18B04473D426E6C9818","codespace":"","code":0,"data":"","raw_log":"[]","logs":[],"info":"","gas_wanted":"0","gas_used":"0","tx":null,"timestamp":"","events":[]}
$ secretcli query compute list-code

@sbellem
Copy link
Contributor

sbellem commented Jul 10, 2023

$ secretcli query tx 96C9FCC2CC4853A8A28111033F478ECC3044D430B98B00F9E8361726609394FF | jq .raw_log
"failed to execute message; message index: 0: Execution error: Error during static Wasm validation: Contract is not CosmWasm v0.10 or v1. To support v0.10 please fix the former two errors, to supports v1 please fix the latter two errors: $[Err(StaticValidationErr { msg: \"Wasm contract doesn't have required export: \\\"cosmwasm_vm_version_3\\\". Exports required by VM: [\\\"cosmwasm_vm_version_3\\\", \\\"query\\\", \\\"init\\\", \\\"handle\\\", \\\"allocate\\\", \\\"deallocate\\\"].\", backtrace: Backtrace(   0: cosmwasm_sgx_vm::errors::vm_error::VmError::static_validation_err\n   1: cosmwasm_sgx_vm::compatability::check_wasm_exports\n   2: cosmwasm_sgx_vm::compatability::check_wasm\n   3: cosmwasm_sgx_vm::cache::CosmCache<S,A,Q>::save_wasm\n   4: go_cosmwasm::do_create\n   5: create\n   6: _cgo_8890a1994f42_C2func_create\n   7: <unknown>\n) }), Err(StaticValidationErr { msg: \"Wasm contract requires unsupported import: \\\"env.GFp_memcmp\\\". Imports supported by VM: [\\\"env.db_read\\\", \\\"env.db_write\\\", \\\"env.db_remove\\\", \\\"env.canonicalize_address\\\", \\\"env.humanize_address\\\", \\\"env.query_chain\\\", \\\"env.secp256k1_verify\\\", \\\"env.secp256k1_recover_pubkey\\\", \\\"env.secp256k1_sign\\\", \\\"env.ed25519_verify\\\", \\\"env.ed25519_batch_verify\\\", \\\"env.ed25519_sign\\\", \\\"env.db_scan\\\", \\\"env.db_next\\\", \\\"env.debug_print\\\"].\", backtrace: Backtrace(   0: cosmwasm_sgx_vm::errors::vm_error::VmError::static_validation_err\n   1: cosmwasm_sgx_vm::compatability::check_wasm_imports\n   2: cosmwasm_sgx_vm::compatability::check_wasm\n   3: cosmwasm_sgx_vm::cache::CosmCache<S,A,Q>::save_wasm\n   4: go_cosmwasm::do_create\n   5: create\n   6: _cgo_8890a1994f42_C2func_create\n   7: <unknown>\n) }), Ok(()), Err(StaticValidationErr { msg: \"Wasm contract requires unsupported import: \\\"env.GFp_memcmp\\\". Imports supported by VM: [\\\"env.db_read\\\", \\\"env.db_write\\\", \\\"env.db_remove\\\", \\\"env.addr_validate\\\", \\\"env.addr_canonicalize\\\", \\\"env.addr_humanize\\\", \\\"env.secp256k1_verify\\\", \\\"env.secp256k1_recover_pubkey\\\", \\\"env.secp256k1_sign\\\", \\\"env.ed25519_verify\\\", \\\"env.ed25519_batch_verify\\\", \\\"env.ed25519_sign\\\", \\\"env.debug\\\", \\\"env.query_chain\\\", \\\"env.db_scan\\\", \\\"env.db_next\\\", \\\"env.gas_evaporate\\\", \\\"env.check_gas\\\"].\", backtrace: Backtrace(   0: cosmwasm_sgx_vm::errors::vm_error::VmError::static_validation_err\n   1: cosmwasm_sgx_vm::compatability::check_wasm_imports\n   2: cosmwasm_sgx_vm::compatability::check_wasm\n   3: cosmwasm_sgx_vm::cache::CosmCache<S,A,Q>::save_wasm\n   4: go_cosmwasm::do_create\n   5: create\n   6: _cgo_8890a1994f42_C2func_create\n   7: <unknown>\n) })]: create contract failed"

@njeans
Copy link
Collaborator Author

njeans commented Aug 21, 2023

closed in favor of #17

@njeans njeans closed this Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants