utxostack/rgbpp-sdk

[Discussion] Type proxies in btc: `Address` and `Pubkey`

Opened this issue · 2 comments

We can define type proxies for Address and Pubkey to improve the code readability of the btc lib. However, it would take some time to search for relevant code and update it. So, the discussion is: Do you think we should define the two type proxies, and do you think the change is worthwhile?

From this:

interface SendXProps {
  from: string;
  fromPubkey?: string;
  pubkeyMap?: Record<string, string>; // Record<address, pubkey>
}

Which can be refactored to this:

type Address = string;
type Pubkey = string;

interface SendXProps {
  from: Address;
  fromPubkey?: Pubkey;
  pubkeyMap?: Record<Address, Pubkey>;
}

Original commented at: #228 (comment)

The original comment was discussing about how to make the type of pubkeyMap more clear, in the PR I've chosen a simpler solution to only define a type AddressToPubkeyMap with an explanation comment:

/**
 * Type: Record<Address, Pubkey>
 * The map of address and pubkey, usually for recognizing the P2TR inputs in the transaction.
 */
type AddressToPubkeyMap = Record<string, string>;

interface SendXProps {
  from: string;
  fromPubkey?: string;
  pubkeyMap?: AddressToPubkeyMap;
}

I think refactoring is the icing on the cake. The amount of work required and whether it is worth spending time depends on your evaluation.

If you think the input-output ratio is low, we can do nothing for it.

I want to emphasize that this is just a suggestion.

in the PR I've chosen a simpler solution to only define a type AddressToPubkeyMap with an explanation comment: