Merge pull request #4056 from mempool/mononaut/compressed-p2pk
Add support for compressed p2pk addresses
This commit is contained in:
		
						commit
						ecd80aad6a
					
				@ -183,15 +183,18 @@ class WebsocketHandler {
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (parsedMessage && parsedMessage['track-address']) {
 | 
			
		||||
            if (/^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,100}|[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|[0-9a-fA-F]{130})$/
 | 
			
		||||
            if (/^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,100}|[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64})$/
 | 
			
		||||
              .test(parsedMessage['track-address'])) {
 | 
			
		||||
              let matchedAddress = parsedMessage['track-address'];
 | 
			
		||||
              if (/^[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}$/.test(parsedMessage['track-address'])) {
 | 
			
		||||
                matchedAddress = matchedAddress.toLowerCase();
 | 
			
		||||
              }
 | 
			
		||||
              if (/^[0-9a-fA-F]{130}$/.test(parsedMessage['track-address'])) {
 | 
			
		||||
              if (/^04[a-fA-F0-9]{128}$/.test(parsedMessage['track-address'])) {
 | 
			
		||||
                client['track-address'] = null;
 | 
			
		||||
                client['track-scriptpubkey'] = '41' + matchedAddress + 'ac';
 | 
			
		||||
              } else if (/^|(02|03)[a-fA-F0-9]{64}$/.test(parsedMessage['track-address'])) {
 | 
			
		||||
                client['track-address'] = null;
 | 
			
		||||
                client['track-scriptpubkey'] = '21' + matchedAddress + 'ac';
 | 
			
		||||
              } else {
 | 
			
		||||
                client['track-address'] = matchedAddress;
 | 
			
		||||
                client['track-scriptpubkey'] = null;
 | 
			
		||||
 | 
			
		||||
@ -64,12 +64,12 @@ export class AddressPreviewComponent implements OnInit, OnDestroy {
 | 
			
		||||
          this.address = null;
 | 
			
		||||
          this.addressInfo = null;
 | 
			
		||||
          this.addressString = params.get('id') || '';
 | 
			
		||||
          if (/^[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|[A-F0-9]{130}$/.test(this.addressString)) {
 | 
			
		||||
          if (/^[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64}$/.test(this.addressString)) {
 | 
			
		||||
            this.addressString = this.addressString.toLowerCase();
 | 
			
		||||
          }
 | 
			
		||||
          this.seoService.setTitle($localize`:@@address.component.browser-title:Address: ${this.addressString}:INTERPOLATION:`);
 | 
			
		||||
 | 
			
		||||
          return (this.addressString.match(/[a-f0-9]{130}/)
 | 
			
		||||
          return (this.addressString.match(/04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64}/)
 | 
			
		||||
              ? this.electrsApiService.getPubKeyAddress$(this.addressString)
 | 
			
		||||
              : this.electrsApiService.getAddress$(this.addressString)
 | 
			
		||||
            ).pipe(
 | 
			
		||||
 | 
			
		||||
@ -72,7 +72,7 @@ export class AddressComponent implements OnInit, OnDestroy {
 | 
			
		||||
          this.addressInfo = null;
 | 
			
		||||
          document.body.scrollTo(0, 0);
 | 
			
		||||
          this.addressString = params.get('id') || '';
 | 
			
		||||
          if (/^[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|[A-F0-9]{130}$/.test(this.addressString)) {
 | 
			
		||||
          if (/^[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100}|04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64}$/.test(this.addressString)) {
 | 
			
		||||
            this.addressString = this.addressString.toLowerCase();
 | 
			
		||||
          }
 | 
			
		||||
          this.seoService.setTitle($localize`:@@address.component.browser-title:Address: ${this.addressString}:INTERPOLATION:`);
 | 
			
		||||
@ -84,7 +84,7 @@ export class AddressComponent implements OnInit, OnDestroy {
 | 
			
		||||
          )
 | 
			
		||||
          .pipe(
 | 
			
		||||
            switchMap(() => (
 | 
			
		||||
              this.addressString.match(/[a-f0-9]{130}/)
 | 
			
		||||
              this.addressString.match(/04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64}/)
 | 
			
		||||
              ? this.electrsApiService.getPubKeyAddress$(this.addressString)
 | 
			
		||||
              : this.electrsApiService.getAddress$(this.addressString)
 | 
			
		||||
            ).pipe(
 | 
			
		||||
@ -118,7 +118,7 @@ export class AddressComponent implements OnInit, OnDestroy {
 | 
			
		||||
          this.isLoadingAddress = false;
 | 
			
		||||
          this.isLoadingTransactions = true;
 | 
			
		||||
          return address.is_pubkey
 | 
			
		||||
              ? this.electrsApiService.getScriptHashTransactions$('41' + address.address + 'ac')
 | 
			
		||||
              ? this.electrsApiService.getScriptHashTransactions$((address.address.length === 66 ? '21' : '41') + address.address + 'ac')
 | 
			
		||||
              : this.electrsApiService.getAddressTransactions$(address.address);
 | 
			
		||||
        }),
 | 
			
		||||
        switchMap((transactions) => {
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ export class SearchFormComponent implements OnInit {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  regexAddress = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[A-z]{2,5}1[a-zA-HJ-NP-Z0-9]{39,59}|[0-9a-fA-F]{130})$/;
 | 
			
		||||
  regexAddress = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[A-z]{2,5}1[a-zA-HJ-NP-Z0-9]{39,59}|04[a-fA-F0-9]{128}|(02|03)[a-fA-F0-9]{64})$/;
 | 
			
		||||
  regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/;
 | 
			
		||||
  regexTransaction = /^([a-fA-F0-9]{64})(:\d+)?$/;
 | 
			
		||||
  regexBlockheight = /^[0-9]{1,9}$/;
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@
 | 
			
		||||
            <ng-template ngFor let-vin let-vindex="index" [ngForOf]="tx.vin.slice(0, getVinLimit(tx))" [ngForTrackBy]="trackByIndexFn">
 | 
			
		||||
              <tr [ngClass]="{
 | 
			
		||||
                'assetBox': (assetsMinimal && vin.prevout && assetsMinimal[vin.prevout.asset] && !vin.is_coinbase && vin.prevout.scriptpubkey_address && tx._unblinded) || inputIndex === vindex,
 | 
			
		||||
                'highlight': this.address !== '' && (vin.prevout?.scriptpubkey_address === this.address || (vin.prevout?.scriptpubkey_type === 'p2pk' && vin.prevout?.scriptpubkey.slice(2, 132) === this.address))
 | 
			
		||||
                'highlight': this.address !== '' && (vin.prevout?.scriptpubkey_address === this.address || (vin.prevout?.scriptpubkey_type === 'p2pk' && vin.prevout?.scriptpubkey.slice(2, -2) === this.address))
 | 
			
		||||
              }">
 | 
			
		||||
                <td class="arrow-td">
 | 
			
		||||
                  <ng-template [ngIf]="vin.prevout === null && !vin.is_pegin" [ngIfElse]="hasPrevout">
 | 
			
		||||
@ -56,8 +56,8 @@
 | 
			
		||||
                      <span i18n="transactions-list.peg-in">Peg-in</span>
 | 
			
		||||
                    </ng-container>
 | 
			
		||||
                    <ng-container *ngSwitchCase="vin.prevout && vin.prevout.scriptpubkey_type === 'p2pk'">
 | 
			
		||||
                      <span>P2PK <a class="address p2pk-address" [routerLink]="['/address/' | relativeUrl, vin.prevout.scriptpubkey.slice(2, 132)]" title="{{ vin.prevout.scriptpubkey.slice(2, 132) }}">
 | 
			
		||||
                        <app-truncate [text]="vin.prevout.scriptpubkey.slice(2, 132)" [lastChars]="8"></app-truncate>
 | 
			
		||||
                      <span>P2PK <a class="address p2pk-address" [routerLink]="['/address/' | relativeUrl, vin.prevout.scriptpubkey.slice(2, -2)]" title="{{ vin.prevout.scriptpubkey.slice(2, -2) }}">
 | 
			
		||||
                        <app-truncate [text]="vin.prevout.scriptpubkey.slice(2, -2)" [lastChars]="8"></app-truncate>
 | 
			
		||||
                      </a></span>
 | 
			
		||||
                    </ng-container>
 | 
			
		||||
                    <ng-container *ngSwitchDefault>
 | 
			
		||||
@ -184,7 +184,7 @@
 | 
			
		||||
            <ng-template ngFor let-vout let-vindex="index" [ngForOf]="tx.vout.slice(0, getVoutLimit(tx))" [ngForTrackBy]="trackByIndexFn">
 | 
			
		||||
              <tr [ngClass]="{
 | 
			
		||||
                'assetBox': assetsMinimal && assetsMinimal[vout.asset] && vout.scriptpubkey_address && tx.vin && !tx.vin[0].is_coinbase && tx._unblinded || outputIndex === vindex,
 | 
			
		||||
                'highlight': this.address !== '' && (vout.scriptpubkey_address === this.address || (vout.scriptpubkey_type === 'p2pk' && vout.scriptpubkey.slice(2, 132) === this.address))
 | 
			
		||||
                'highlight': this.address !== '' && (vout.scriptpubkey_address === this.address || (vout.scriptpubkey_type === 'p2pk' && vout.scriptpubkey.slice(2, -2) === this.address))
 | 
			
		||||
              }">
 | 
			
		||||
                <td class="address-cell">
 | 
			
		||||
                  <a class="address" *ngIf="vout.scriptpubkey_address; else pubkey_type" [routerLink]="['/address/' | relativeUrl, vout.scriptpubkey_address]" title="{{ vout.scriptpubkey_address }}">
 | 
			
		||||
@ -192,8 +192,8 @@
 | 
			
		||||
                  </a>
 | 
			
		||||
                  <ng-template #pubkey_type>
 | 
			
		||||
                    <ng-container *ngIf="vout.scriptpubkey_type === 'p2pk'; else scriptpubkey_type">
 | 
			
		||||
                      P2PK <a class="address p2pk-address" [routerLink]="['/address/' | relativeUrl, vout.scriptpubkey.slice(2, 132)]" title="{{ vout.scriptpubkey.slice(2, 132) }}">
 | 
			
		||||
                        <app-truncate [text]="vout.scriptpubkey.slice(2, 132)" [lastChars]="8"></app-truncate>
 | 
			
		||||
                      P2PK <a class="address p2pk-address" [routerLink]="['/address/' | relativeUrl, vout.scriptpubkey.slice(2, -2)]" title="{{ vout.scriptpubkey.slice(2, -2) }}">
 | 
			
		||||
                        <app-truncate [text]="vout.scriptpubkey.slice(2, -2)" [lastChars]="8"></app-truncate>
 | 
			
		||||
                      </a>
 | 
			
		||||
                    </ng-container>
 | 
			
		||||
                  </ng-template>
 | 
			
		||||
 | 
			
		||||
@ -67,7 +67,8 @@ export class ElectrsApiService {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getPubKeyAddress$(pubkey: string): Observable<Address> {
 | 
			
		||||
    return this.getScriptHash$('41' + pubkey + 'ac').pipe(
 | 
			
		||||
    const scriptpubkey = (pubkey.length === 130 ? '41' : '21') + pubkey + 'ac';
 | 
			
		||||
    return this.getScriptHash$(scriptpubkey).pipe(
 | 
			
		||||
      switchMap((scripthash: ScriptHash) => {
 | 
			
		||||
        return of({
 | 
			
		||||
          ...scripthash,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user