Skip to content

Commit

Permalink
fix: fixes #233
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Wyndham committed Sep 2, 2020
1 parent 8521d37 commit 6933db9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assembly/sdk/env/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { u128 } from "..";

export namespace env {
// #############
// # Registers #
Expand Down Expand Up @@ -454,4 +456,19 @@ export namespace env {
export function storage_has_key(key_len: u64, key_ptr: u64): u64 {
return _storage_has_key(key_len, key_ptr);
}

export function validator_stake(account_id: string): u128 {
let data = new Uint8Array(sizeof<u128>());
let id = String.UTF8.encode(account_id);
let id_ptr = changetype<u64>(id);
_validator_stake(id.byteLength, id_ptr, data.dataStart);
return u128.from(data);
}

// /// Returns the total stake of validators in the current epoch.
export function validator_total_stake(): u128 {
let data = new Uint8Array(sizeof<u128>());
_validator_total_stake(data.dataStart);
return u128.from(data);
}
}
16 changes: 16 additions & 0 deletions assembly/sdk/env/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,19 @@ declare function _storage_remove(
@external("env", "storage_has_key")
@global
declare function _storage_has_key(key_len: u64, key_ptr: u64): u64;

// ###############
// # Validator API #
// ###############

/// For a given account return its current stake. If the account is not a validator, returns 0.
//@ts-ignore
@external("env", "validator_stake")
@global
declare function _validator_stake(id_len: u64, id_ptr: u64, data_ptr: u64): u64;

/// Returns the total stake of validators in the current epoch.
//@ts-ignore
@external("env", "validator_total_stake")
@global
declare function _validator_total_stake(data_ptr: u64): u64;

0 comments on commit 6933db9

Please sign in to comment.