Skip to content

Commit

Permalink
add Mintlayer ChangeTokenMetadataUri command input
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Sep 10, 2024
1 parent bdc40aa commit 0829525
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 78 deletions.
29 changes: 19 additions & 10 deletions common/protob/messages-mintlayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,17 @@ message MintlayerAccountTxInput {
* @embed
*/
message MintlayerAccountCommandTxInput {
repeated MintlayerAddressPath address_n = 1; // BIP-32 path to derive the key from master node
required string address = 2; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
optional uint32 sequence = 3 [default=0xffffffff]; // sequence
required uint64 nonce = 4; // incrementing account nonce
optional MintlayerMintTokens mint = 5; // mint tokens
optional MintlayerUnmintTokens unmint = 6; // unmint tokens
optional MintlayerLockTokenSupply lock_token_supply = 7; // lock token supply
optional MintlayerFreezeToken freeze_token = 8; // freeze supply
optional MintlayerUnfreezeToken unfreeze_token = 9; // unfreeze supply
optional MintlayerChangeTokenAuhtority change_token_authority = 10; // change token authority
repeated MintlayerAddressPath address_n = 1; // BIP-32 path to derive the key from master node
required string address = 2; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
optional uint32 sequence = 3 [default=0xffffffff]; // sequence
required uint64 nonce = 4; // incrementing account nonce
optional MintlayerMintTokens mint = 5; // mint tokens
optional MintlayerUnmintTokens unmint = 6; // unmint tokens
optional MintlayerLockTokenSupply lock_token_supply = 7; // lock token supply
optional MintlayerFreezeToken freeze_token = 8; // freeze supply
optional MintlayerUnfreezeToken unfreeze_token = 9; // unfreeze supply
optional MintlayerChangeTokenAuhtority change_token_authority = 10; // change token authority
optional MintlayerChangeTokenMetadataUri change_token_metadata_uri = 11; // change token metadata uri
}

/** Data type for output value coins or token
Expand Down Expand Up @@ -243,6 +244,14 @@ message MintlayerChangeTokenAuhtority {
required string destination = 2; // destination for the new authority
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerChangeTokenMetadataUri {
required bytes token_id = 1; // token id
required bytes metadata_uri = 2; // new metadata uri
}

/** Data type for transaction output to be signed.
* @embed
*/
Expand Down
25 changes: 19 additions & 6 deletions core/embed/rust/src/mintlayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ extern "C" fn mintlayer_encode_account_command_input(
};
AccountCommand::ChangeTokenAuthority(token_id, destination)
}
7 => {
AccountCommand::ChangeTokenMetadataUri(token_id, data.to_vec())
}
_ => return MintlayerErrorCode::InvalidAccountCommand.into(),
};

Expand Down Expand Up @@ -1324,29 +1327,39 @@ enum IsTokenUnfreezable {
Yes,
}

type OrderId = H256;
type TokenId = H256;

#[derive(Encode)]
enum AccountCommand {
// Create certain amount of tokens and add them to circulating supply
#[codec(index = 0)]
MintTokens(H256, Amount),
MintTokens(TokenId, Amount),
// Take tokens out of circulation. Not the same as Burn because unminting means that certain
// amount of tokens is no longer supported by underlying fiat currency, which can only be
// done by the authority.
#[codec(index = 1)]
UnmintTokens(H256),
UnmintTokens(TokenId),
// After supply is locked tokens cannot be minted or unminted ever again.
// Works only for Lockable tokens supply.
#[codec(index = 2)]
LockTokenSupply(H256),
LockTokenSupply(TokenId),
// Freezing token forbids any operation with all the tokens (except for optional unfreeze)
#[codec(index = 3)]
FreezeToken(H256, IsTokenUnfreezable),
FreezeToken(TokenId, IsTokenUnfreezable),
// By unfreezing token all operations are available for the tokens again
#[codec(index = 4)]
UnfreezeToken(H256),
UnfreezeToken(TokenId),
// Change the authority who can authorize operations for a token
#[codec(index = 5)]
ChangeTokenAuthority(H256, Destination),
ChangeTokenAuthority(TokenId, Destination),
#[codec(index = 6)]
ConcludeOrder(OrderId),
#[codec(index = 7)]
FillOrder(OrderId, OutputValue, Destination),
// Change token metadata uri
#[codec(index = 8)]
ChangeTokenMetadataUri(TokenId, parity_scale_codec::alloc::vec::Vec<u8>),
}

#[derive(Encode)]
Expand Down
8 changes: 4 additions & 4 deletions core/src/apps/mintlayer/get_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ async def get_address(msg: MintlayerGetAddress, keychain: Keychain) -> Mintlayer

from apps.common import paths

from .helpers import address_from_public_key
from trezor.crypto.bech32 import bech32_encode, Encoding

HRP = "bnb"
HRP = "mtc"
address_n = msg.address_n # local_cache_attribute

await paths.validate_path(keychain, address_n)

node = keychain.derive(address_n)
pubkey = node.public_key()
address = address_from_public_key(pubkey, HRP)
address = bech32_encode(HRP, pubkey, Encoding.BECH32M)
if msg.show_display:
await show_address(
address,
path=paths.address_n_to_str(address_n),
account=paths.get_account_name("BNB", address_n, PATTERNS[0], SLIP44_ID),
account=None,
chunkify=bool(msg.chunkify),
)

Expand Down
1 change: 1 addition & 0 deletions core/src/apps/mintlayer/sign_tx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def _sanitize_tx_input(txi: MintlayerTxInput) -> MintlayerTxInput:
and cmd.freeze_token is None
and cmd.unfreeze_token is None
and cmd.lock_token_supply is None
and cmd.change_token_metadata_uri is None
and cmd.change_token_authority is None)
if no_cmd:
raise DataError("No account command present")
Expand Down
4 changes: 4 additions & 0 deletions core/src/apps/mintlayer/sign_tx/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ async def step4_serialize_inputs(self) -> Tuple[List[bytes], List[bytes]]:
command = 5
token_id = x.change_token_authority.token_id
data = mintlayer_decode_address_to_bytes(x.change_token_authority.destination)
elif x.change_token_metadata_uri:
command = 5
token_id = x.change_token_metadata_uri.token_id
data = x.change_token_metadata_uri.metadata_uri
else:
raise Exception("unknown account command")

Expand Down
18 changes: 18 additions & 0 deletions core/src/trezor/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions python/src/trezorlib/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0829525

Please sign in to comment.