0xa1::weighted_signer
WeightedSigner
pub_key
weight
new
default
peel
validate
lt
use 0x2::address;
use 0x2::bcs;
WeightedSigner
struct WeightedSigner has copy, drop, store
pub_key: vector<u8>
weight: u128
const EInvalidPubKeyLength: vector<u8> = [105, 110, 118, 97, 108, 105, 100, 32, 112, 117, 98, 108, 105, 99, 32, 107, 101, 121, 32, 108, 101, 110, 103, 116, 104, 58, 32, 101, 120, 112, 101, 99, 116, 101, 100, 32, 51, 51, 32, 98, 121, 116, 101, 115];
const EInvalidWeight: vector<u8> = [105, 110, 118, 97, 108, 105, 100, 32, 119, 101, 105, 103, 104, 116, 58, 32, 101, 120, 112, 101, 99, 116, 101, 100, 32, 110, 111, 110, 45, 122, 101, 114, 111, 32, 118, 97, 108, 117, 101];
Length of a public key
const PUB_KEY_LENGTH: u64 = 33;
pub_key
public fun pub_key(self: &weighted_signer::WeightedSigner): vector<u8>
public fun pub_key(self: &WeightedSigner): vector<u8> {
self.pub_key
}
weight
public fun weight(self: &weighted_signer::WeightedSigner): u128
public fun weight(self: &WeightedSigner): u128 {
self.weight
}
new
public(friend) fun new(pub_key: vector<u8>, weight: u128): weighted_signer::WeightedSigner
public(package) fun new(pub_key: vector<u8>, weight: u128): WeightedSigner {
assert!(pub_key.length() == PUB_KEY_LENGTH, EInvalidPubKeyLength);
WeightedSigner { pub_key, weight }
}
default
Empty weighted signer
public(friend) fun default(): weighted_signer::WeightedSigner
public(package) fun default(): WeightedSigner {
let mut pub_key = @0x0.to_bytes();
pub_key.push_back(0);
WeightedSigner {
pub_key,
weight: 0,
}
}
peel
public(friend) fun peel(bcs: &mut bcs::BCS): weighted_signer::WeightedSigner
public(package) fun peel(bcs: &mut BCS): WeightedSigner {
let pub_key = bcs.peel_vec_u8();
let weight = bcs.peel_u128();
new(pub_key, weight)
}
validate
public(friend) fun validate(self: &weighted_signer::WeightedSigner)
public(package) fun validate(self: &WeightedSigner) {
assert!(self.weight != 0, EInvalidWeight);
}
lt
Check if self.signer is less than other.signer as bytes
public(friend) fun lt(self: &weighted_signer::WeightedSigner, other: &weighted_signer::WeightedSigner): bool
public(package) fun lt(self: &WeightedSigner, other: &WeightedSigner): bool {
let mut i = 0;
while (i < PUB_KEY_LENGTH) {
if (self.pub_key[i] < other.pub_key[i]) {
return true
} else if (self.pub_key[i] > other.pub_key[i]) {
return false
};
i = i + 1;
};
false
}