-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from SCMusson/feat_cert_script
Methods to add certificate scripts for smart staking
- Loading branch information
Showing
6 changed files
with
235 additions
and
2 deletions.
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