-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-coin-ada): support vote delegation
- Loading branch information
1 parent
7e4f921
commit 6395115
Showing
12 changed files
with
218 additions
and
58 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
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
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,56 @@ | ||
import { BaseKey, TransactionType } from '@bitgo/sdk-core'; | ||
import { BaseCoin as CoinConfig } from '@bitgo/statics'; | ||
import { TransactionBuilder } from './transactionBuilder'; | ||
import { Transaction } from './transaction'; | ||
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; | ||
import adaUtils from './utils'; | ||
|
||
export class VoteDelegationBuilder extends TransactionBuilder { | ||
constructor(_coinConfig: Readonly<CoinConfig>) { | ||
super(_coinConfig); | ||
this._type = TransactionType.VoteDelegation; | ||
} | ||
|
||
protected get transactionType(): TransactionType { | ||
return TransactionType.VoteDelegation; | ||
} | ||
|
||
/** @inheritdoc */ | ||
initBuilder(tx: Transaction): void { | ||
super.initBuilder(tx); | ||
} | ||
|
||
/** | ||
* Creates the proper certificates needed to delegate a user's vote to a given DRep | ||
* | ||
* @param stakingPublicKey The user's public stake key | ||
* @param dRepId The DRep ID of the DRep we will delegate vote to | ||
*/ | ||
addVoteDelegationCertificate(stakingPublicKey: string, dRepId: string): this { | ||
const stakeCredential = CardanoWasm.Credential.from_keyhash( | ||
CardanoWasm.PublicKey.from_bytes(Buffer.from(stakingPublicKey, 'hex')).hash() | ||
); | ||
const voteDelegationCert = CardanoWasm.Certificate.new_vote_delegation( | ||
CardanoWasm.VoteDelegation.new(stakeCredential, adaUtils.getDRepFromDRepId(dRepId)) | ||
); | ||
this._certs.push(voteDelegationCert); | ||
return this; | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected async buildImplementation(): Promise<Transaction> { | ||
const tx = await super.buildImplementation(); | ||
tx.setTransactionType(TransactionType.StakingActivate); | ||
return tx; | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected fromImplementation(rawTransaction: string): Transaction { | ||
return super.fromImplementation(rawTransaction); | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected signImplementation(key: BaseKey): Transaction { | ||
return super.signImplementation(key); | ||
} | ||
} |
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
Oops, something went wrong.