utxostack / rgbpp-sdk

Utilities for Bitcoin and RGB++ asset integration
ISC License
53 stars 16 forks source link

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

Open ShookLyngs opened 3 months ago

ShookLyngs commented 3 months ago

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: https://github.com/ckb-cell/rgbpp-sdk/pull/228#discussion_r1642535163

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;
}
duanyytop commented 3 months ago

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.

Flouse commented 3 months ago

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