Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPrefixHeader does not work for all AddressType values #140

Open
boorac opened this issue Jun 23, 2023 · 3 comments
Open

GetPrefixHeader does not work for all AddressType values #140

boorac opened this issue Jun 23, 2023 · 3 comments

Comments

@boorac
Copy link

boorac commented Jun 23, 2023

GetPrefixHeader does not work for all values. Examples that do not work, but are valid addresses (as defined in https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019#test-vectors):

  1. addr1yx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerkr0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shs2z78ve // type-02
  2. addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu // type-05
  3. addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k // type-04
  4. stake178phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcccycj5 // type-15

It seems that updating the below snippet could be sufficient:

public static string GetPrefixHeader(AddressType addressType)
    {
      switch (addressType)
      {
        case AddressType.Base:
          return "addr";
        case AddressType.Script:
          return "addr";
        case AddressType.ScriptWithScriptDelegation:
          return "addr";
        case AddressType.Enterprise:
          return "addr";
        case AddressType.EnterpriseScript:
          return "addr";
        case AddressType.Stake:
          return "stake";
        default:
          throw new Exception("Unknown address type");
      }
    }
@hguy23
Copy link

hguy23 commented Jun 25, 2023

public static string GetPrefixHeader(AddressType addressType)
    {
      switch (addressType)
      {
        case AddressType.Base:
        case AddressType.Script:
        case AddressType.ScriptWithScriptDelegation:
        case AddressType.Enterprise:
        case AddressType.EnterpriseScript:
          return "addr";
        case AddressType.Stake:
          return "stake";
        default:
          throw new Exception("Unknown address type");
      }
    }

You can do that instead of repeating same return @boorac

@boorac
Copy link
Author

boorac commented Jun 27, 2023

@frytik thanks for the tip. The solution to the issue (I assume) would be to add the missing branches to the switch statement you proposed.

@nothingalike
Copy link
Member

@frytik

Unfortunately there's a little more to it

addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu // type-05
addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k // type-04

These require us to support the Pointer address type which we do not. If you want to add support for your needs, im sure everyone would appreciate it.

Docs for doing this, came from your link

In an address, a chain pointer refers to a point of the chain containing a stake key registration certificate. A point is identified by 3 coordinates:

An absolute slot number
A transaction index (within that slot)
A (delegation) certificate index (within that transaction)
These coordinates form a concise way of referring to a stake key (typically half the size of a stake key hash). They are serialized as three variable-length positive numbers following the ABNF grammar here below:

POINTER = VARIABLE-LENGTH-UINT ; slot number
        | VARIABLE-LENGTH-UINT ; transaction index
        | VARIABLE-LENGTH-UINT ; certificate index

VARIABLE-LENGTH-UINT = (%b1 | UINT7 | VARIABLE-LENGTH-UINT) 
                     / (%b0 | UINT7)

UINT7 = 7BIT 

The other type addresses

addr1yx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerkr0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shs2z78ve // type-02
stake178phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcccycj5 // type-15

These have to do with the ScriptHash which we do support and these two should be easier to add support for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants