axelar_gateway::weighted_signersWeightedSignerspeelvalidatehashsignersthresholdnoncevalidate_signerstotal_weightvalidate_thresholduse axelar_gateway::bytes32;
use axelar_gateway::weighted_signer;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::bcs;
use sui::hash;
use sui::hex;
WeightedSignerspublic struct WeightedSigners has copy, drop, store
Errors ——
#[error]
const EInvalidSignersLength: vector<u8> = b"invalid signers length: expected at least 1 signer";
#[error]
const EInvalidThreshold: vector<u8> = b"invalid threshold: expected non-zero value and less than or equal to the total weight of the signers";
#[error]
const EInvalidSignerOrder: vector<u8> = b"invalid signer order: signers must be in ascending order by their public key";
peelPackage Functions
—————–
Decode a WeightedSigners from the BCS encoded bytes.
public(package) fun peel(bcs: &mut sui::bcs::BCS): axelar_gateway::weighted_signers::WeightedSigners
public(package) fun peel(bcs: &mut BCS): WeightedSigners {
let len = bcs.peel_vec_length();
assert!(len > 0, EInvalidSignersLength);
WeightedSigners {
signers: vector::tabulate!(len, |_| weighted_signer::peel(bcs)),
threshold: bcs.peel_u128(),
nonce: bytes32::peel(bcs),
}
}
validateValidates the weighted signers. The following must be true:
public(package) fun validate(self: &axelar_gateway::weighted_signers::WeightedSigners)
public(package) fun validate(self: &WeightedSigners) {
self.validate_signers();
self.validate_threshold();
}
hashpublic(package) fun hash(self: &axelar_gateway::weighted_signers::WeightedSigners): axelar_gateway::bytes32::Bytes32
public(package) fun hash(self: &WeightedSigners): Bytes32 {
bytes32::from_bytes(hash::keccak256(&bcs::to_bytes(self)))
}
signerspublic(package) fun signers(self: &axelar_gateway::weighted_signers::WeightedSigners): &vector<axelar_gateway::weighted_signer::WeightedSigner>
public(package) fun signers(self: &WeightedSigners): &vector<WeightedSigner> {
&self.signers
}
thresholdpublic(package) fun threshold(self: &axelar_gateway::weighted_signers::WeightedSigners): u128
public(package) fun threshold(self: &WeightedSigners): u128 {
self.threshold
}
noncepublic(package) fun nonce(self: &axelar_gateway::weighted_signers::WeightedSigners): axelar_gateway::bytes32::Bytes32
public(package) fun nonce(self: &WeightedSigners): Bytes32 {
self.nonce
}
validate_signersInternal Functions
—–
Validates the order of the signers and the length of the signers.
The signers must be in ascending order by their public key.
Otherwise, the error EInvalidSignersLength is raised.
fun validate_signers(self: &axelar_gateway::weighted_signers::WeightedSigners)
fun validate_signers(self: &WeightedSigners) {
assert!(!self.signers.is_empty(), EInvalidSignersLength);
let mut previous = &weighted_signer::default();
self.signers.do_ref!(|signer| {
signer.validate();
assert!(previous.lt(signer), EInvalidSignerOrder);
previous = signer;
});
}
total_weightCalculates the total weight of the signers.
fun total_weight(self: &axelar_gateway::weighted_signers::WeightedSigners): u128
fun total_weight(self: &WeightedSigners): u128 {
self.signers.fold!<WeightedSigner, u128>(0, |acc, signer| acc + signer.weight())
}
validate_thresholdValidates the threshold.
The threshold must be greater than zero and less than or equal to the total
weight of the signers.
Otherwise, the error EInvalidThreshold is raised.
fun validate_threshold(self: &axelar_gateway::weighted_signers::WeightedSigners)
fun validate_threshold(self: &WeightedSigners) {
assert!(self.threshold != 0 && self.total_weight() >= self.threshold, EInvalidThreshold);
}