Skip to content

Commit

Permalink
feat: made some public functions package functions (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos authored Nov 25, 2024
1 parent ada6fd9 commit b68989a
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 110 deletions.
7 changes: 2 additions & 5 deletions move/axelar_gateway/sources/types/message.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public struct Message has copy, drop, store {
}

/// -----------------
/// Public Functions
/// Package Functions
/// -----------------
public fun new(
public(package) fun new(
source_chain: String,
message_id: String,
source_address: String,
Expand All @@ -36,9 +36,6 @@ public fun new(
}
}

/// -----------------
/// Package Functions
/// -----------------
public(package) fun peel(bcs: &mut BCS): Message {
// TODO: allow UTF-8 strings? Or keep it as more generic bytes?
let source_chain = bcs.peel_vec_u8().to_ascii_string();
Expand Down
15 changes: 6 additions & 9 deletions move/axelar_gateway/sources/types/proof.move
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,20 @@ const ESignerNotFound: vector<u8> =
#[error]
const ERedundantSignaturesProvided: vector<u8> =
b"redundant signatures provided";

// ----------------
// Public Functions
// ----------------
// -----------------
// Package Functions
// -----------------
/// The signers of the proof
public fun signers(proof: &Proof): &WeightedSigners {
public(package) fun signers(proof: &Proof): &WeightedSigners {
&proof.signers
}

/// The proof signatures
public fun signatures(proof: &Proof): &vector<Signature> {
public(package) fun signatures(proof: &Proof): &vector<Signature> {
&proof.signatures
}

// -----------------
// Package Functions
// -----------------
public(package) fun new_signature(bytes: vector<u8>): Signature {
assert!(bytes.length() == SIGNATURE_LENGTH, EInvalidSignatureLength);

Expand Down
7 changes: 5 additions & 2 deletions move/axelar_gateway/sources/types/weighted_signer.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ public struct WeightedSigner has copy, drop, store {
weight: u128,
}

public fun pub_key(self: &WeightedSigner): vector<u8> {
// -----------------
// Package Functions
// -----------------
public(package) fun pub_key(self: &WeightedSigner): vector<u8> {
self.pub_key
}

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

Expand Down
8 changes: 4 additions & 4 deletions move/gas_service/sources/versioned/gas_service_v0.move
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ fun take(
// Test Only
// ---------
#[test_only]
public fun version_control_mut(self: &mut GasService_v0): &mut VersionControl {
public(package) fun version_control_mut(self: &mut GasService_v0): &mut VersionControl {
&mut self.version_control
}

#[test_only]
public fun balance(self: &GasService_v0): &Balance<SUI> {
public(package) fun balance(self: &GasService_v0): &Balance<SUI> {
&self.balance
}

#[test_only]
public fun balance_mut(self: &mut GasService_v0): &mut Balance<SUI> {
public(package) fun balance_mut(self: &mut GasService_v0): &mut Balance<SUI> {
&mut self.balance
}

#[test_only]
public fun destroy_for_testing(self: GasService_v0) {
public(package) fun destroy_for_testing(self: GasService_v0) {
let GasService_v0 { balance, version_control: _ } = self;
balance.destroy_for_testing();
}
13 changes: 5 additions & 8 deletions move/its/sources/types/address_tracker.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public struct InterchainAddressTracker has store {
trusted_addresses: Table<String, String>,
}

// -------
// Getters
// -------
// -----------------
// Package Functions
// -----------------
/// Get the trusted address for a chain.
public fun trusted_address(
public(package) fun trusted_address(
self: &InterchainAddressTracker,
chain_name: String,
): &String {
Expand All @@ -36,17 +36,14 @@ public fun trusted_address(
}

/// Check if the given address is trusted for the given chain.
public fun is_trusted_address(
public(package) fun is_trusted_address(
self: &InterchainAddressTracker,
chain_name: String,
addr: String,
): bool {
self.trusted_addresses.contains(chain_name) && self.trusted_addresses[chain_name] == addr
}

// -----------------
// Package Functions
// -----------------
/// Create a new interchain address tracker.
public(package) fun new(ctx: &mut TxContext): InterchainAddressTracker {
InterchainAddressTracker {
Expand Down
5 changes: 3 additions & 2 deletions move/its/sources/types/coin_info.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public fun from_metadata<T>(metadata: CoinMetadata<T>): CoinInfo<T> {
}
}

// === Views ===

// -----
// Views
// -----
public fun name<T>(self: &CoinInfo<T>): String {
self.name
}
Expand Down
5 changes: 4 additions & 1 deletion move/its/sources/types/trusted_addresses.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public fun new(
}
}

public fun destroy(self: TrustedAddresses): (vector<String>, vector<String>) {
/// -----------------
/// Package Functions
/// -----------------
public(package) fun destroy(self: TrustedAddresses): (vector<String>, vector<String>) {
let TrustedAddresses { trusted_chains, trusted_addresses } = self;
(trusted_chains, trusted_addresses)
}
Expand Down
15 changes: 1 addition & 14 deletions test/testdata/interface_axelar_gateway_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,5 @@
]
}
},
"publicFunctions": {
"new": {
"name": "new",
"visibility": "public",
"params": {
"source_chain#0#0": "String",
"message_id#0#0": "String",
"source_address#0#0": "String",
"destination_id#0#0": "address",
"payload_hash#0#0": "Bytes32"
},
"returnType": "Message"
}
}
"publicFunctions": {}
}
19 changes: 1 addition & 18 deletions test/testdata/interface_axelar_gateway_proof.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,5 @@
]
}
},
"publicFunctions": {
"signers": {
"name": "signers",
"visibility": "public",
"params": {
"proof#0#0": "&Proof"
},
"returnType": "&WeightedSigners"
},
"signatures": {
"name": "signatures",
"visibility": "public",
"params": {
"proof#0#0": "&Proof"
},
"returnType": "&vector<Signature>"
}
}
"publicFunctions": {}
}
19 changes: 1 addition & 18 deletions test/testdata/interface_axelar_gateway_weighted_signer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,5 @@
]
}
},
"publicFunctions": {
"pub_key": {
"name": "pub_key",
"visibility": "public",
"params": {
"self#0#0": "&WeightedSigner"
},
"returnType": "vector<u8>"
},
"weight": {
"name": "weight",
"visibility": "public",
"params": {
"self#0#0": "&WeightedSigner"
},
"returnType": "u128"
}
}
"publicFunctions": {}
}
22 changes: 1 addition & 21 deletions test/testdata/interface_its_address_tracker.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,5 @@
]
}
},
"publicFunctions": {
"trusted_address": {
"name": "trusted_address",
"visibility": "public",
"params": {
"self#0#0": "&InterchainAddressTracker",
"chain_name#0#0": "String"
},
"returnType": "&String"
},
"is_trusted_address": {
"name": "is_trusted_address",
"visibility": "public",
"params": {
"self#0#0": "&InterchainAddressTracker",
"chain_name#0#0": "String",
"addr#0#0": "String"
},
"returnType": "bool"
}
}
"publicFunctions": {}
}
8 changes: 0 additions & 8 deletions test/testdata/interface_its_trusted_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
"trusted_addresses#0#0": "vector<String>"
},
"returnType": "TrustedAddresses"
},
"destroy": {
"name": "destroy",
"visibility": "public",
"params": {
"self#0#0": "TrustedAddresses"
},
"returnType": "vector<String> * vector<String>"
}
}
}

0 comments on commit b68989a

Please sign in to comment.