-
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.
- Loading branch information
Showing
10 changed files
with
366 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const INPUT_MAX_COUNT = 6; | ||
export const OUTPUT_MAX_COUNT = 6; | ||
|
||
export const INPUT_COUNT_BYTE_LEN = 4n; | ||
export const OUTPUT_COUNT_BYTE_LEN = 4n; | ||
|
||
export const TX_HASH_BYTE_LEN = 32n; | ||
export const OUTPUT_INDEX_BYTE_LEN = 4n; | ||
export const PREVOUT_BYTE_LEN = TX_HASH_BYTE_LEN + OUTPUT_INDEX_BYTE_LEN; |
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,43 @@ | ||
import { | ||
assert, | ||
ByteString, | ||
hash256, | ||
int2ByteString, | ||
len, | ||
method, | ||
Sha256, | ||
SmartContractLib, | ||
toByteString, | ||
} from 'scrypt-ts'; | ||
import { BridgeTx } from '../types'; | ||
|
||
export class BridgeUtils extends SmartContractLib { | ||
@method() | ||
static getTxId(tx: BridgeTx): Sha256 { | ||
assert(len(tx.version) == 4n); | ||
assert(len(tx.bridgeInput) == 0n || len(tx.bridgeInput) == 37n); | ||
assert(len(tx.aggregatorInput) == 0n || len(tx.aggregatorInput) == 37n); | ||
assert(len(tx.feeInput) >= 37n); | ||
assert(tx.bridgeOutputAmount > 0n); | ||
assert(len(tx.bridgeOutputLocking) == 35n); | ||
assert(len(tx.dataHash) == 32n); | ||
assert(len(tx.locktime) == 4n); | ||
|
||
let inputCount = 1n; | ||
if (len(tx.bridgeInput) > 0n) { | ||
inputCount += 1n; | ||
} | ||
if (len(tx.aggregatorInput) > 0n) { | ||
inputCount += 1n; | ||
} | ||
|
||
return hash256(tx.version + int2ByteString(inputCount)); | ||
} | ||
|
||
@method() | ||
static buildPrevout(prevTx: BridgeTx): ByteString { | ||
const prevTxId = this.getTxId(prevTx); | ||
// prevTxId + outputIndex (00000000) | ||
return prevTxId + toByteString('00000000'); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.