-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Methods to add certificate scripts for smart staking #388
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c41b5f4
initial changes
SCMusson b3ad8e7
CERT to CERTIFICATE
SCMusson 3161ef9
automatically set redeemer index to last added certificate
SCMusson b7960c3
Merge branch 'Python-Cardano:main' into feat_cert_script
SCMusson bed9167
formatting
SCMusson 3753fb6
add test
SCMusson a944c2a
more tests to bring coverage patch to 100%
SCMusson c95fb61
Basic test
SCMusson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
integration-test/plutus_scripts/pass_certifying_and_rewarding.plutus
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 @@ | ||
5901e9010000323232323232323232323232322232323232323232323232323374a90001bb1498c8c8ccccd400c01001401840084004030030488888c8c8c94ccd5cd19180d88009980c180aa8012400c2930992999ab9a32301c100133019301650034801052615333573464603820029404c00452613263357389201136e6f7420612076616c696420707572706f7365004988c00852624984004c0454004405840584c98cd5ce2481104e616d654572726f723a207e626f6f6c004984c98cd5ce2481144e616d654572726f723a2076616c696461746f72004984c98cd5ce2481124e616d654572726f723a20707572706f7365004984c98cd5ce2481104e616d654572726f723a20646174756d004984c98cd5ce2481124e616d654572726f723a20636f6e74657874004984c98cd5ce2481144e616d654572726f723a20526577617264696e67004984c98cd5ce2481154e616d654572726f723a2043657274696679696e67004980080088c010c0200048c0140040108c018c94ccd55cf800899319ab9c49010a496e6465784572726f72004984d5d1000800919000a80091aab9d3754002e1c8d55cf1baa00123253335573e002264c66ae712410a496e6465784572726f72004984d5d0800800919ba548018cd5d028009bb14988cdd2a400866ae814004dd8a4c1 |
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,97 @@ | ||
import os | ||
import time | ||
|
||
import cbor2 | ||
from retry import retry | ||
|
||
from pycardano import * | ||
|
||
from .base import TEST_RETRIES, TestBase | ||
|
||
|
||
class TestDelegation(TestBase): | ||
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4)) | ||
def test_stake_delegation(self): | ||
with open("./plutus_scripts/pass_certifying_and_rewarding.plutus", "r") as f: | ||
script_hex = f.read() | ||
stake_script = PlutusV2Script(bytes.fromhex(script_hex)) | ||
cert_script_hash = plutus_script_hash(stake_script) | ||
address = Address( | ||
self.payment_key_pair.verification_key.hash(), | ||
cert_script_hash, | ||
self.NETWORK, | ||
) | ||
|
||
utxos = self.chain_context.utxos(address) | ||
|
||
if not utxos: | ||
giver_address = Address(self.payment_vkey.hash(), network=self.NETWORK) | ||
|
||
builder = TransactionBuilder(self.chain_context) | ||
|
||
builder.add_input_address(giver_address) | ||
builder.add_output(TransactionOutput(address, 44000000000)) | ||
|
||
signed_tx = builder.build_and_sign([self.payment_skey], giver_address) | ||
|
||
print("############### Transaction created ###############") | ||
print(signed_tx) | ||
print(signed_tx.to_cbor_hex()) | ||
print("############### Submitting transaction ###############") | ||
self.chain_context.submit_tx(signed_tx) | ||
|
||
time.sleep(3) | ||
|
||
stake_credential = StakeCredential(cert_script_hash) | ||
stake_registration = StakeRegistration(stake_credential) | ||
pool_hash = PoolKeyHash(bytes.fromhex(os.environ.get("POOL_ID").strip())) | ||
stake_delegation = StakeDelegation(stake_credential, pool_keyhash=pool_hash) | ||
|
||
builder = TransactionBuilder(self.chain_context) | ||
|
||
builder.add_input_address(address) | ||
builder.add_output(TransactionOutput(address, 35000000)) | ||
builder.certificates = [stake_registration, stake_delegation] | ||
redeemer = Redeemer(0) | ||
builder.add_certificate_script(stake_script, redeemer=redeemer) | ||
|
||
signed_tx = builder.build_and_sign( | ||
[self.payment_key_pair.signing_key], | ||
address, | ||
) | ||
|
||
print("############### Transaction created ###############") | ||
print(signed_tx) | ||
print(signed_tx.to_cbor_hex()) | ||
print("############### Submitting transaction ###############") | ||
self.chain_context.submit_tx(signed_tx) | ||
|
||
|
||
# time.sleep(8) | ||
# | ||
# builder = TransactionBuilder(self.chain_context) | ||
# | ||
# builder.add_input_address(address) | ||
# | ||
# stake_address = Address( | ||
# staking_part=cert_script_hash, | ||
# network=self.NETWORK, | ||
# ) | ||
# | ||
# builder.withdrawals = Withdrawals({bytes(stake_address): 0}) | ||
# | ||
# builder.add_output(TransactionOutput(address, 1000000)) | ||
# redeemer = Redeemer(0) | ||
# builder.add_withdrawal_script(stake_script, redeemer=redeemer) | ||
# | ||
# signed_tx = builder.build_and_sign( | ||
# [self.payment_key_pair.signing_key], | ||
# address, | ||
# ) | ||
# | ||
# print("############### Transaction created ###############") | ||
# print(signed_tx) | ||
# print(signed_tx.to_cbor_hex()) | ||
# print("############### Submitting transaction ###############") | ||
# self.chain_context.submit_tx(signed_tx) | ||
# |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do I understand correctly that the redeemer index is supposed to be directly set by the user according to the order in which they add certificates? (this is the way that it is currently implemented here)
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.
Yes, that's how cardano-cli does it. I was thinking that if this causes confusion then the best alternative would be to create an
add_certificate
method with optional arguments to add a script and redeemer. I assumed that would be a more major change that might be out of scope for this PR.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.
Are there script-less certificates?
Either way we can add this upon request
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.
The majority of delegation seems to be done with certificates built from stake keys rather than scripts. I think smart staking is relatively niche at the moment.