-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(offer): validate vin index on PSBTs
- Loading branch information
Showing
7 changed files
with
113 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { api } from "../Api"; | ||
import { BadRequestError, method } from "../JsonRpc"; | ||
import { utils } from "../Orderbook/Utilities"; | ||
|
||
api.register< | ||
{ | ||
offer: string; | ||
}, | ||
{ | ||
type: string; | ||
offer: any; | ||
} | ||
>( | ||
"DecodeOffer", | ||
method(async ({ offer }) => { | ||
const psbt = utils.psbt.decode(offer); | ||
if (psbt !== undefined) { | ||
return { type: "psbt", offer: psbt }; | ||
} | ||
const tx = utils.raw.decode(offer); | ||
if (tx !== undefined) { | ||
return { type: "raw", offer: tx }; | ||
} | ||
throw new BadRequestError(); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as btc from "bitcoinjs-lib"; | ||
|
||
export const raw = { | ||
decode, | ||
}; | ||
|
||
/** | ||
* Attempt to retrieve a raw unsigned transaction from the offer string. | ||
* | ||
* @param offer - Encoded offer transaction. | ||
* | ||
* @returns The raw tx or undefined if it could not be parsed. | ||
*/ | ||
function decode(offer: string): any | undefined { | ||
try { | ||
return btc.Transaction.fromHex(offer); | ||
} catch (error) { | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import "./Methods/Orderbook"; | ||
import "./Methods/IPFS"; | ||
import "./Methods/Offer"; | ||
|
||
import debug from "debug"; | ||
|
||
|