axelar-cgp-sui

Module 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::hex;

Struct WeightedSigner

public struct WeightedSigner has copy, drop, store
Fields
pub_key: vector<u8>
weight: u128

Constants

Length of a public key

const PUB_KEY_LENGTH: u64 = 33;

#[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";

Function pub_key

public(package) fun pub_key(self: &axelar_gateway::weighted_signer::WeightedSigner): vector<u8>
Implementation
public(package) fun pub_key(self: &WeightedSigner): vector<u8> {
    self.pub_key
}

Function weight

public(package) fun weight(self: &axelar_gateway::weighted_signer::WeightedSigner): u128
Implementation
public(package) fun weight(self: &WeightedSigner): u128 {
    self.weight
}

Function new

public(package) fun new(pub_key: vector<u8>, weight: u128): axelar_gateway::weighted_signer::WeightedSigner
Implementation
public(package) fun new(pub_key: vector<u8>, weight: u128): WeightedSigner {
    assert!(pub_key.length() == PUB_KEY_LENGTH, EInvalidPubKeyLength);
    WeightedSigner { pub_key, weight }
}

Function default

Empty weighted signer

public(package) fun default(): axelar_gateway::weighted_signer::WeightedSigner
Implementation
public(package) fun default(): WeightedSigner {
    let mut pub_key = @0x0.to_bytes();
    pub_key.push_back(0);
    WeightedSigner {
        pub_key,
        weight: 0,
    }
}

Function peel

public(package) fun peel(bcs: &mut sui::bcs::BCS): axelar_gateway::weighted_signer::WeightedSigner
Implementation
public(package) fun peel(bcs: &mut BCS): WeightedSigner {
    let pub_key = bcs.peel_vec_u8();
    let weight = bcs.peel_u128();
    new(pub_key, weight)
}

Function validate

public(package) fun validate(self: &axelar_gateway::weighted_signer::WeightedSigner)
Implementation
public(package) fun validate(self: &WeightedSigner) {
    assert!(self.weight != 0, EInvalidWeight);
}

Function lt

Check if self.signer is less than other.signer as bytes

public(package) fun lt(self: &axelar_gateway::weighted_signer::WeightedSigner, other: &axelar_gateway::weighted_signer::WeightedSigner): bool
Implementation
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
}