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
#[error]
const EInvalidPubKeyLength: vector<u8> = b"invalid public key length: expected 33 bytes";
#[error]
const EInvalidWeight: vector<u8> = b"invalid weight: expected non-zero value";
Length of a public key
const PUB_KEY_LENGTH: u64 = 33;
pub_key
public(friend) fun pub_key(self: &weighted_signer::WeightedSigner): vector<u8>
public(package) fun pub_key(self: &WeightedSigner): vector<u8> {
self.pub_key
}
weight
public(friend) fun weight(self: &weighted_signer::WeightedSigner): u128
public(package) 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
}