axelar-cgp-sui

Module 0xa1::weighted_signer

use 0x2::address;
use 0x2::bcs;

Struct WeightedSigner

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

Constants

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;

Function pub_key

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

Function weight

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

Function new

public(friend) fun new(pub_key: vector<u8>, weight: u128): 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(friend) fun default(): 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(friend) fun peel(bcs: &mut bcs::BCS): 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(friend) fun validate(self: &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(friend) fun lt(self: &weighted_signer::WeightedSigner, other: &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
}