aptos: formatting fixes
This commit is contained in:
parent
3c914c725a
commit
6da8e4ae7d
|
@ -23,7 +23,7 @@ module token_bridge::normalized_amount {
|
|||
public fun normalize(amount: u64, decimals: u8): NormalizedAmount {
|
||||
if (decimals > 8) {
|
||||
let n = decimals - 8;
|
||||
while (n > 0){
|
||||
while (n > 0) {
|
||||
amount = amount / 10;
|
||||
n = n - 1;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ module token_bridge::normalized_amount {
|
|||
let NormalizedAmount { amount } = amount;
|
||||
if (decimals > 8) {
|
||||
let n = decimals - 8;
|
||||
while (n > 0){
|
||||
while (n > 0) {
|
||||
amount = amount * 10;
|
||||
n = n - 1;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ module token_bridge::state {
|
|||
|
||||
let state = borrow_global_mut<State>(@token_bridge);
|
||||
let native_infos = &mut state.native_infos;
|
||||
if (table::contains(native_infos, token_address)){
|
||||
if (table::contains(native_infos, token_address)) {
|
||||
//TODO: throw error, because we should only be able to set native asset type info once?
|
||||
table::remove(native_infos, token_address);
|
||||
};
|
||||
|
|
|
@ -98,7 +98,7 @@ module token_bridge::asset_meta {
|
|||
|
||||
// Construct a seed using AssetMeta fields for creating a new resource account
|
||||
// N.B. seed is a product of coin native chain and native address
|
||||
public(friend) fun create_seed(asset_meta: &AssetMeta): vector<u8>{
|
||||
public(friend) fun create_seed(asset_meta: &AssetMeta): vector<u8> {
|
||||
let token_chain = get_token_chain(asset_meta);
|
||||
let token_address = get_token_address(asset_meta);
|
||||
let seed = vector::empty<u8>();
|
||||
|
|
|
@ -18,7 +18,7 @@ module token_bridge::token_bridge {
|
|||
init_internal(signer_cap);
|
||||
}
|
||||
|
||||
fun init_internal(signer_cap: SignerCapability){
|
||||
fun init_internal(signer_cap: SignerCapability) {
|
||||
let emitter_cap = wormhole::register_emitter();
|
||||
init_token_bridge_state(signer_cap, emitter_cap);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ module token_bridge::transfer_tokens {
|
|||
recipient: vector<u8>,
|
||||
relayer_fee: u64,
|
||||
nonce: u64
|
||||
) {
|
||||
) {
|
||||
let coins = coin::withdraw<CoinType>(sender, amount);
|
||||
let wormhole_fee = wormhole::state::get_message_fee();
|
||||
let wormhole_fee_coins = coin::withdraw<AptosCoin>(sender, wormhole_fee);
|
||||
|
@ -43,7 +43,7 @@ module token_bridge::transfer_tokens {
|
|||
recipient: ExternalAddress,
|
||||
relayer_fee: u64,
|
||||
nonce: u64
|
||||
): u64 {
|
||||
): u64 {
|
||||
let result = transfer_tokens_internal<CoinType>(coins, relayer_fee);
|
||||
let (token_chain, token_address, normalized_amount, normalized_relayer_fee)
|
||||
= transfer_result::destroy(result);
|
||||
|
@ -70,7 +70,7 @@ module token_bridge::transfer_tokens {
|
|||
recipient: ExternalAddress,
|
||||
nonce: u64,
|
||||
payload: vector<u8>
|
||||
): u64 {
|
||||
): u64 {
|
||||
let result = transfer_tokens_internal<CoinType>(coins, 0);
|
||||
let (token_chain, token_address, normalized_amount, _)
|
||||
= transfer_result::destroy(result);
|
||||
|
@ -104,13 +104,13 @@ module token_bridge::transfer_tokens {
|
|||
fun transfer_tokens_internal<CoinType>(
|
||||
coins: Coin<CoinType>,
|
||||
relayer_fee: u64,
|
||||
): TransferResult {
|
||||
): TransferResult {
|
||||
|
||||
// transfer coin to token_bridge
|
||||
if (!coin::is_account_registered<CoinType>(@token_bridge)){
|
||||
if (!coin::is_account_registered<CoinType>(@token_bridge)) {
|
||||
coin::register<CoinType>(&state::token_bridge_signer());
|
||||
};
|
||||
if (!coin::is_account_registered<AptosCoin>(@token_bridge)){
|
||||
if (!coin::is_account_registered<AptosCoin>(@token_bridge)) {
|
||||
coin::register<AptosCoin>(&state::token_bridge_signer());
|
||||
};
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ module wormhole::external_address {
|
|||
e.external_address
|
||||
}
|
||||
|
||||
public fun pad_left_32(input: &vector<u8>): vector<u8>{
|
||||
public fun pad_left_32(input: &vector<u8>): vector<u8> {
|
||||
let len = vector::length<u8>(input);
|
||||
assert!(len <= 32, E_VECTOR_TOO_LONG);
|
||||
let ret = vector::empty<u8>();
|
||||
let zeros_remaining = 32 - len;
|
||||
while (zeros_remaining > 0){
|
||||
while (zeros_remaining > 0) {
|
||||
vector::push_back<u8>(&mut ret, 0);
|
||||
zeros_remaining = zeros_remaining - 1;
|
||||
};
|
||||
|
|
|
@ -44,7 +44,7 @@ module wormhole::serialize {
|
|||
vector::append(buf, v);
|
||||
}
|
||||
|
||||
public fun serialize_vector(buf: &mut vector<u8>, v: vector<u8>){
|
||||
public fun serialize_vector(buf: &mut vector<u8>, v: vector<u8>) {
|
||||
vector::append(buf, v)
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ module wormhole::test_serialize {
|
|||
use std::vector;
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u8(){
|
||||
fun test_serialize_u8() {
|
||||
let u = 0x12;
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u8(&mut s, u);
|
||||
|
@ -71,7 +71,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u16(){
|
||||
fun test_serialize_u16() {
|
||||
let u = u16::from_u64((0x1234 as u64));
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u16(&mut s, u);
|
||||
|
@ -82,7 +82,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u32(){
|
||||
fun test_serialize_u32() {
|
||||
let u = u32::from_u64((0x12345678 as u64));
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u32(&mut s, u);
|
||||
|
@ -93,7 +93,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u64(){
|
||||
fun test_serialize_u64() {
|
||||
let u = 0x1234567812345678;
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u64(&mut s, u);
|
||||
|
@ -104,7 +104,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u128(){
|
||||
fun test_serialize_u128() {
|
||||
let u = 0x12345678123456781234567812345678;
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u128(&mut s, u);
|
||||
|
@ -115,7 +115,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_u256(){
|
||||
fun test_serialize_u256() {
|
||||
let u = u256::add(u256::shl(u256::from_u128(0x47386917590997937461700473756125), 128), u256::from_u128(0x9876));
|
||||
let s = vector::empty();
|
||||
serialize::serialize_u256(&mut s, u);
|
||||
|
@ -124,7 +124,7 @@ module wormhole::test_serialize {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fun test_serialize_vector(){
|
||||
fun test_serialize_vector() {
|
||||
let x = vector::empty<u8>();
|
||||
let y = vector::empty<u8>();
|
||||
vector::push_back<u8>(&mut x, 0x12);
|
||||
|
|
|
@ -49,7 +49,7 @@ module wormhole::structs {
|
|||
recovery_id: u8,
|
||||
guardian_index: u8
|
||||
): Signature {
|
||||
Signature{ sig, recovery_id, guardian_index }
|
||||
Signature { sig, recovery_id, guardian_index }
|
||||
}
|
||||
|
||||
public fun get_address(guardian: &Guardian): guardian_pubkey::Address {
|
||||
|
|
|
@ -114,7 +114,7 @@ module wormhole::wormhole {
|
|||
// performs aptos coin registration too, so it's possible that this is
|
||||
// already performed, in which case we just skip
|
||||
// (thanks ottersec for point this out)
|
||||
if (!coin::is_account_registered<AptosCoin>(signer::address_of(&wormhole))){
|
||||
if (!coin::is_account_registered<AptosCoin>(signer::address_of(&wormhole))) {
|
||||
coin::register<AptosCoin>(&wormhole);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue