Skip to content

Commit

Permalink
Merge pull request #2151 from Emurgo/ergo-address-type-fix
Browse files Browse the repository at this point in the history
Fix for Ergo unknown address type error in develop
  • Loading branch information
vsubhuman committed Jun 8, 2021
2 parents 28a022d + 1b04fc3 commit 64a3d46
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 19 deletions.
Expand Up @@ -92,8 +92,8 @@ export function ergoAddressToType(
address: RustModule.SigmaRust.NetworkAddress,
): CoreAddressT {
switch (address.address().address_type_prefix()) {
case RustModule.SigmaRust.AddressTypePrefix.P2PK: return CoreAddressTypes.ERGO_P2PK;
case RustModule.SigmaRust.AddressTypePrefix.Pay2SH: return CoreAddressTypes.ERGO_P2SH;
case RustModule.SigmaRust.AddressTypePrefix.P2Pk: return CoreAddressTypes.ERGO_P2PK;
case RustModule.SigmaRust.AddressTypePrefix.Pay2Sh: return CoreAddressTypes.ERGO_P2SH;
case RustModule.SigmaRust.AddressTypePrefix.Pay2S: return CoreAddressTypes.ERGO_P2S;
default: throw new Error(`${nameof(ergoAddressToType)} unknown Ergo address type ${address.to_base58()}`);
}
Expand Down
135 changes: 118 additions & 17 deletions packages/yoroi-extension/flow-typed/npm/ergo-lib-wasm-browser_vx.x.x.js
Expand Up @@ -57,8 +57,10 @@ type ErgoTxJson = {|
|};

/**
* Flowtype definitions for ergo_lib_wasm
* Generated by Flowgen from a Typescript Definition
* Repo: http://github.com/joarwilk/flowgen
* Flowgen v1.11.0
* @flow
*/
declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into module
/**
Expand Down Expand Up @@ -88,8 +90,8 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
*/

declare export var AddressTypePrefix: {|
+P2PK: 1,
+Pay2SH: 2,
+P2Pk: 1,
+Pay2Sh: 2,
+Pay2S: 3,
|};

Expand Down Expand Up @@ -218,12 +220,70 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
*/
to_ergo_tree(): ErgoTree;
}
/**
* Block header
*/
declare export class BlockHeader {
free(): void;

/**
* Parse from JSON (Node API)
* @param {string} json
* @returns {BlockHeader}
*/
static from_json(json: string): BlockHeader;
}
/**
* Collection of BlockHeaders
*/
declare export class BlockHeaders {
free(): void;

/**
* parse BlockHeader array from JSON (Node API)
* @param {any[]} boxes
* @returns {BlockHeaders}
*/
static from_json(boxes: any[]): BlockHeaders;

/**
* Create new collection with one element
* @param {BlockHeader} b
*/
constructor(b: BlockHeader): this;

/**
* Returns the number of elements in the collection
* @returns {number}
*/
len(): number;

/**
* Add an element to the collection
* @param {BlockHeader} b
*/
add(b: BlockHeader): void;

/**
* Returns the element of the collection with a given index
* @param {number} index
* @returns {BlockHeader}
*/
get(index: number): BlockHeader;
}
/**
* Box id (32-byte digest)
*/
declare export class BoxId {
free(): void;

/**
* Parse box id (32 byte digest) from base16-encoded string
* @param {string} box_id_str
* @returns {BoxId}
*/
static from_str(box_id_str: string): BoxId;

/**
* Base16 encoded string
* @returns {string}
Expand Down Expand Up @@ -382,6 +442,19 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
* @returns {Contract}
*/
static pay_to_address(recipient: Address): Contract;

/**
* Compiles a contract from ErgoScript source code
* @param {string} source
* @returns {Contract}
*/
static compile(source: string): Contract;

/**
* Get the ErgoTree of the contract
* @returns {ErgoTree}
*/
ergo_tree(): ErgoTree;
}
/**
* Inputs, that are used to enrich script context, but won't be spent by the transaction
Expand All @@ -390,6 +463,12 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
free(): void;

/**
* Parse box id (32 byte digest) from base16-encoded string
* @param {BoxId} box_id
*/
constructor(box_id: BoxId): this;

/**
* Get box id
* @returns {BoxId}
*/
Expand Down Expand Up @@ -783,26 +862,24 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
* @returns {ErgoBox}
*/
get(index: number): ErgoBox;
}
declare export class BlockHeader {
static from_json(json: string): BlockHeader;
}
declare export class PreHeader {
static from_block_header(block_header: BlockHeader): PreHeader;
}
/**
* TBD
*/
declare export class ErgoStateContext {
}
/**
* Blockchain state (last headers, etc.)
*/
declare export class ErgoStateContext {
free(): void;

/**
* Create new context from pre-header
* @param {PreHeader} pre_header
*/
constructor(pre_header: PreHeader): this;

/**
* empty (dummy) context (for signing P2PK tx only)
* @returns {ErgoStateContext}
*/
static dummy(): ErgoStateContext;

constructor(pre_header: PreHeader): this;
}
/**
* The root of ErgoScript IR. Serialized instances of this class are self sufficient and can be passed around.
Expand All @@ -829,6 +906,12 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
* @returns {Uint8Array}
*/
to_bytes(): Uint8Array;

/**
* Returns Base16-encoded serialized bytes
* @returns {string}
*/
to_base16_bytes(): string;
}
/**
* Wrapper for i64 for JS/TS
Expand Down Expand Up @@ -976,6 +1059,20 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
address(): Address;
}
/**
* Block header with the current `spendingTransaction`, that can be predicted
* by a miner before it's formation
*/
declare export class PreHeader {
free(): void;

/**
* Create using data from block header
* @param {BlockHeader} block_header
* @returns {PreHeader}
*/
static from_block_header(block_header: BlockHeader): PreHeader;
}
/**
* Proof of correctness of tx spending
*/
declare export class ProverResult {
Expand Down Expand Up @@ -1161,6 +1258,10 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod
*/
static from_str(str: string): TokenId;

/**
* Base16 encoded string
* @returns {string}
*/
to_str(): string;
}
/**
Expand Down Expand Up @@ -1250,7 +1351,7 @@ declare module 'ergo-lib-wasm-browser' { // need to wrap flowgen output into mod

/**
* Creates new TxBuilder
* `box_selection` - selected input boxes (via [`BoxSelector`])
* `box_selection` - selected input boxes (via [`super::box_selector`])
* `output_candidates` - output boxes to be "created" in this transaction,
* `current_height` - chain height that will be used in additionally created boxes (change, miner's fee, etc.),
* `fee_amount` - miner's fee,
Expand Down

0 comments on commit 64a3d46

Please sign in to comment.