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

feat: Add created/updated at block heights to registry #458

Merged
merged 8 commits into from
Jan 4, 2024
3 changes: 3 additions & 0 deletions registry/contract/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions registry/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
borsh = "1.0.0"
getrandom = { version = "0.2", features = ["js"] }
near-sdk = "5.0.0-alpha.1"
uint = { version = "0.9.3", default-features = false }
registry-types = { path = "../types", features = ["nearsdk"] }
Expand Down
40 changes: 40 additions & 0 deletions registry/contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,43 @@ Add multisig deployment administration for Data team and SREs (DAO?).
./build.sh
near deploy --wasmFile ./target/wasm32-unknown-unknown/release/registry.wasm --accountId registry.queryapi.testnet
```

## Issues encountered while building

### Clang

The default version of `clang` on MacOS cannot build `wasm32-unknown-unknown`, therefore another version must be installed:
```sh
brew install llvm
```
and can be used via setting the `CC` environment variable:
```sh
CC="/opt/homebrew/Cellar/llvm/17.0.6/bin/clang" cargo build --target wasm32-unknown-unknown
```

### near-primitives usize
The `near-primitives` crate internally hard-codes `usize` as 8bits, this becomes a problem when targetting 32bit architecture (wasm32), which expects a `usize` of 4bits. To Bypass this issue the following patch can be applied to the local version of the crate in `~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/near-primitives-0.17.0/src/rand.rs`:
```patch
diff --git a/core/primitives/src/rand.rs b/core/primitives/src/rand.rs
index a79c8fd1b..17978a199 100644
--- a/core/primitives/src/rand.rs
+++ b/core/primitives/src/rand.rs
@@ -57,16 +57,7 @@ impl WeightedIndex {
}

pub fn sample(&self, seed: [u8; 32]) -> usize {
- let usize_seed = Self::copy_8_bytes(&seed[0..8]);
- let balance_seed = Self::copy_16_bytes(&seed[8..24]);
- let uniform_index = usize::from_le_bytes(usize_seed) % self.aliases.len();
- let uniform_weight = Balance::from_le_bytes(balance_seed) % self.weight_sum;
-
- if uniform_weight < self.no_alias_odds[uniform_index] {
- uniform_index
- } else {
- self.aliases[uniform_index] as usize
- }
+ 0
}

pub fn get_aliases(&self) -> &[u64] {
```
Loading