-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove circular dependencies from cli
- Loading branch information
1 parent
e9e626d
commit 4a29e42
Showing
5 changed files
with
71 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DEFAULT_MAX_ID_SEARCH_INDEX } from './argparse'; | ||
import { CLINetworkAdapter } from './network'; | ||
import * as blockstack from 'blockstack'; | ||
import { TransactionSigner } from 'blockstack'; | ||
import * as bitcoinjs from 'bitcoinjs-lib'; | ||
|
||
let maxIDSearchIndex = DEFAULT_MAX_ID_SEARCH_INDEX; | ||
|
||
export function getMaxIDSearchIndex() { | ||
return maxIDSearchIndex; | ||
} | ||
|
||
export function setMaxIDSearchIndex(index: number) { | ||
maxIDSearchIndex = index; | ||
} | ||
|
||
export class CLITransactionSigner implements TransactionSigner { | ||
address: string; | ||
isComplete: boolean; | ||
|
||
constructor(address = '') { | ||
this.address = address; | ||
this.isComplete = false; | ||
} | ||
|
||
getAddress(): Promise<string> { | ||
return Promise.resolve().then(() => this.address); | ||
} | ||
|
||
signTransaction(_txIn: bitcoinjs.TransactionBuilder, _signingIndex: number): Promise<void> { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
return Promise.resolve().then(() => {}); | ||
} | ||
|
||
signerVersion(): number { | ||
return 0; | ||
} | ||
} | ||
|
||
/* | ||
* Get a private key's address. Honor the 01 to compress the public key | ||
* @privateKey (string) the hex-encoded private key | ||
*/ | ||
export function getPrivateKeyAddress( | ||
network: CLINetworkAdapter, | ||
privateKey: string | CLITransactionSigner | ||
): string { | ||
if (isCLITransactionSigner(privateKey)) { | ||
const pkts = privateKey; | ||
return pkts.address; | ||
} else { | ||
const pk = privateKey; | ||
const ecKeyPair = blockstack.hexStringToECPair(pk); | ||
return network.coerceAddress(blockstack.ecPairToAddress(ecKeyPair)); | ||
} | ||
} | ||
|
||
export function isCLITransactionSigner( | ||
signer: string | CLITransactionSigner | ||
): signer is CLITransactionSigner { | ||
return (signer as CLITransactionSigner).signerVersion !== 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
4a29e42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: