Skip to content

Commit

Permalink
recreate ensures data ref changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgpai22 committed Feb 2, 2024
1 parent e37bbe3 commit a1431d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
15 changes: 12 additions & 3 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ export class EventFactory {
);
}

public async recreate(signerAddress: string, utxos: UTxO[]): Promise<TxComplete> {
public async recreate(
signerAddress: string,
utxos: UTxO[],
newDataReferences: string[]
): Promise<TxComplete> {
if (!this.providerSetup || !this.objectContractSetup)
throw new Error('setProvider and setObjectContract must be called before recreate');

Expand All @@ -201,7 +205,7 @@ export class EventFactory {
.collectFrom(utxos, this.recreateRedeemer)
.addSigner(signerAddress);

utxos.forEach((utxo) => {
utxos.forEach((utxo, index) => {
let objectDatum;
try {
objectDatum = Data.from<ObjectDatum>(
Expand All @@ -213,10 +217,15 @@ export class EventFactory {
} catch (e) {
throw new Error('issue with datum');
}

if (objectDatum!.data_reference === newDataReferences[index]) {
throw new Error('data references cannot be the same');
}

const newObjectDatum = Data.to<ObjectDatum>(
{
protocol_version: objectDatum!.protocol_version,
data_reference: objectDatum!.data_reference,
data_reference: newDataReferences[index],
event_creation_info:
objectDatum!.event_creation_info === ''
? utxo.txHash
Expand Down
12 changes: 6 additions & 6 deletions src/plutus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export const PLUTUSJSON: PlutusJson = {
preamble: {
title: 'zengate/winter_protocol',
description: "Aiken contracts for project 'zengate/winter_protocol'",
version: '0.0.0',
version: '0.0.2',
plutusVersion: 'v2',
compiler: {
name: 'Aiken',
version: 'v1.0.21-alpha+unknown'
version: 'v1.0.24-alpha+982eff4'
},
license: 'Apache-2.0'
},
Expand Down Expand Up @@ -42,8 +42,8 @@ export const PLUTUSJSON: PlutusJson = {
}
],
compiledCode:
'5910570100003232323232323232323232323232322232222323232533301032323253330133370e9001000899191919191919191919191919191919191919191919191919191919191919299981919b874800007454ccc0c94ccc0c8c94ccc0cccdc3a40006062002264646464a66606e66e1d200030350011323232533303a3370e9001181c000899191919299981f19b8748000c0f00044c8c8c8c94ccc1094ccc1080085288a99821a491a76616c69645f6164615f7472616e73666572203f2046616c73650014a02a666084a666084002294454cc10d2412076616c69645f73696e676c65746f6e5f7472616e73666572203f2046616c73650014a02a66608464a66608666e1d200430410011323232533304653330463370e6eb4c09cc1000f0dd6981398200008a51153304749146646174756d2e70726f746f636f6c5f76657273696f6e203d3d206361737465645f6f75747075745f646174756d2e70726f746f636f6c5f76657273696f6e203f2046616c73650014a02a66608ca66608c66e3cdd7181b182001e1bae3036304000114a22a6608e920142646174756d2e646174615f7265666572656e6365203d3d206361737465645f6f75747075745f646174756d2e646174615f7265666572656e6365203f2046616c73650014a02a66608ca66608ca66608c66e3cdd71812182001e24500153330463371e6eb8c090c100004dd71813982018139820181398200090a5115330474915e7265637265617465645f646174756d2e6576656e745f6372656174696f6e5f696e666f203d3d2073656c665f696e7075742e6f75747075745f7265666572656e63652e7472616e73616374696f6e5f69642e68617368203f2046616c73650014a02a66608c66e3cdd7181218200009bae3024304003c14a22a6608e921487265637265617465645f646174756d2e6576656e745f6372656174696f6e5f696e666f203d3d20646174756d2e6576656e745f6372656174696f6e5f696e666f203f2046616c73650014a0294454cc11d2414976616c69645f6576656e745f6372656174696f6e5f696e666f2873656c665f696e7075742c20646174756d2c206361737465645f6f75747075745f646174756d29203f2046616c73650014a02a66608c66ebcc054c1000f0c054c1000045288a99823a4934646174756d2e7369676e657273203d3d206361737465645f6f75747075745f646174756d2e7369676e657273203f2046616c73650014a029405280a50320023038001304a001303d0011533044040163020303c00314a22a660869214476616c69645f646174756d5f72656372656174696f6e2873656c662c20646174756d2c207265637265617465645f6576656e745f626f785f6f757429203f2046616c73650014a0294052819b87301830173016375660626076004900119b8930193756606060746060607401860326eacc0c0c0e8004c114004c0e000454cc0fc0ec58c05ccc0740048cc044c050dd59817181c000803191980e80091919299982019b87480080044cdc78029bae3046303a00214a0607a002603e6070603e60700026eb0c068c0d8c074c0d80c0dd71820800981a0008a9981d81b8b180d1819980d1819981498198029bae303e00130310011533038034163006300c001300a3756604a605e604a605e0026074002605a0022a660680602c660066eb0c04cc0b0c04cc0b00980785288a99819a493d76616c69645f72656372656174655f6576656e74286d795f6f75747075745f7265666572656e63652c206374782c20646174756d29203f2046616c73650014a02a666064a666064660086026605804c6eb0c004c0b00a05288a99819a481466d7573745f62655f7369676e65645f62795f61745f6c656173745f6f6e65286374782e7472616e73616374696f6e2c20646174756d2e7369676e65727329203f2046616c73650014a02a66606466600c04c056052294454cc0cd24014576616c69645f77696e7465725f666565286374782c207061796d656e745f63726564656e7469616c2c206665655f76616c75655f6c6f76656c61636529203f2046616c73650014a029405280a9998192999819191919191919191919299981d99b8748000c0e40044c8c8c8c94ccc0fccdc3a4000607a002264646464a66608e6094004264a66608866e1cc06cc06801d200213370e00290008a50375a608c0022a6608807e2c6090002646464a66608866e1d200200114bd6f7b63009bab304a303e00230410013302600100233020008488100375c608c00260720022a660800782c601c602800260246eacc0b4c0dcc0b4c0dc004c108004c0d400454cc0f00e058cc02cdd6180d981a180d981a0170131bab303f001303f001303e001303d001303c001302e0013039001302c02614a22a660669212c76616c69645f6275726e286374782c206d795f6f75747075745f7265666572656e636529203f2046616c73650014a02a666064a66606466600c04c056052294454cc0cd2414576616c69645f77696e7465725f666565286374782c207061796d656e745f63726564656e7469616c2c206665655f76616c75655f6c6f76656c61636529203f2046616c73650014a02a666064660086026605804c6eb0c004c0b00a05288a99819a49466d7573745f62655f7369676e65645f62795f61745f6c656173745f6f6e65286374782e7472616e73616374696f6e2c20646174756d2e7369676e65727329203f2046616c73650014a029405281181c181c981c981c8009299981a8008a6103d87a800013374a90001981b181b800a5eb8088c8cc00400400c894ccc0dc0045300103d87a80001323253330353375e602c605e00400a266e9520003303a0024bd70099802002000981d801181c8009119191980080080191299981b8008a501323253330353300800500214a226600800800260760046eb8c0e4004dd6181b181b981b981b981b981b981b981b981b981500111191980080080191299981a8008a501323253330333371e00400a29444cc010010004c0e4008dd7181b80091119299818980698059bac300e302a3011302a00413253330313370e900018178008991929981a180818061bab3023302d001153303430100051533303353330333370e601c00890010a511533034491276c6973742e6c656e6774682876616c69645f6f75747075747329203d3d2031203f2046616c73650014a02a666066a66606666e1cc028c024c020dd598119816800a4000294454cc0d12401596c6973742e6c656e6774682876616c75652e706f6c69636965732876616c75652e776974686f75745f6c6f76656c6163652877696e7465725f6665655f6f75747075742e76616c7565292929203d3d2030203f2046616c73650014a02a66606666e1cc030dd5981198168008028a5115330344914876616c75652e6c6f76656c6163655f6f662877696e7465725f6665655f6f75747075742e76616c756529203d3d206665655f76616c75655f6c6f76656c616365203f2046616c73650014a02940528181c00098158008a998190170b18050009919808000919baf3012302b3012302b0010043758601a6052602060520064660160029101002300d001300100122533302e0011480004cdc0240046600400460620024646464a66605666e1d20020011480004dd698189812801181400099299981519b8748008004530103d87a8000132323300100100222533303100114c103d87a800013232323253330313371e9110000213374a90001981b1ba80014bd700998030030019bad3033003375c6062004606a00460660026eacc0c0c090008c09c004cc0300052201002533302b00114c0103d87a800013374a9000198161816800a5eb80c004004894ccc0a800452000133700900119801001181680091b9933009375000291010023029302a302a00122323300100100322533302900114bd6f7b630099191919299981499b8f007002100313302e337606ea4008dd3000998030030019bab302b003375c6052004605a004605600244646600200200644a666050002297ae0132325333026300500213302b00233004004001133004004001302c002302a00123026001300100122533302300114bd70099812181098128009980100118130009119198008008019129998120008a6103d87a800013232323253330243371e00e004266e95200033029374c00297ae01330060060033756604c0066eb8c090008c0a0008c098004c0040048894cccccc0940084c8c8c8c8cc0254ccc084cdc4001a401c266e0120f2010031533302133710006904001099b813370090400a001a401c2c66e292210128000015333024001133714911035b5d2900004133714911035b5f2000375c604666600e00266ec1300102415d00375266e292210129000042233760980103422c2000375266601001000466e28dd718120009bae3025001375860440046eb4c080004c8cdd81ba83020001374e60420026ea80084c94ccc0880044cdc5245027b7d00002133714911037b5f2000375c604264646600200200644a66604a00220062664466ec130103422c20003752666012012604a00466e29221023a20003330090093026002337146eb8c094004dd71813000981380099801001181400099bb04c10342207d0037520046eac0084c94ccc0880044cdc52441025b5d00002133714911035b5f2000375c604266600a00266ec1300102415d0037520044466ec1300103422c2000375266600c00c00466e28dd718110009bae3023001375800426600a6eb40080044c8cdc524410268270033223233300100100300222253330233371000490000800899191919980300319b8100548008cdc599b80002533302633710004900a0a40c02903719b8b33700002a66604c66e2000520141481805206e0043370c004901019b8300148080cdc700300119b81371a002900119b8a4881012700002375c004444646600200200844a6660440022008266006604800266004004604a00244646600200200644a66603866e1c005200013371491010130000031533301c337100029000099b8a489012d003300200233702900000089980299b8400148050cdc599b803370a002900a240c00066002002444a66603266e2400920001001133300300333708004900a19b8b3370066e14009201448180004c04c028c068004c0340085281808000980098058029180b980c0008a4c2a6602292011856616c696461746f722072657475726e65642066616c736500136563253330103370e90000008a99980a18050028a4c2a6602201e2c2a66602066e1d200200115333014300a005149854cc04403c5854cc04402c58c034010c0040108c94ccc03ccdc3a400000226464646464646464a666036603c00426493191980080080111299980e8008a4c2646600600660420046eb8c07c00454cc06004c58dd6180e000980e0011bae301a001301a002375c603000260300046eb4c058004c02400854cc04002858c030004dd6800918051baa001490128436f6e73747220696e646578206469646e2774206d61746368206120747970652076617269616e74004901334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e206578706563746564004901244578706563746564206f6e20696e636f727265637420436f6e7374722076617269616e740023005375400292011d4578706563746564206e6f206669656c647320666f7220436f6e737472005734ae7155ceaab9e5573eae815d0aba257481',
hash: 'd7d7e2b36f5782524a808cc40c2cfd29d0823a85a367cf67256da68e'
'5906f10100003232323232323232322232222323232533300c323232533300f3370e90010008991919191919191919191919191919191919191919191919299981399b874800005854ccc09cc94ccc0a0cdc3a4000604e002264646464a66605866e1d2000302b0011323232533302f3370e90011817000899191919299981999b8748000c0c80044c8c8c8c94ccc0dc00854ccc0dc0044c94ccc0e0cdc3a4008606e0022646464a66607666e1cdd69813181c81a9bad302630390011533303b33303b3371e6eb8c0bcc0e40d4dd71817981c800a504a22a666076a66607666e3cdd71811981c81aa4410013371e6eb8c08cc0e4004dd71813181c9813181c9813181c809099b8f375c604660720026eb8c08cc0e40d44cdd7980a981c81a980a981c8008a5014a02940c8008c0c4004c0f8004c0d800458c07cc0d400c5280a503370e60326030602e6eacc0a8c0d0009200233712602a6eacc0a4c0ccc0a4c0cc030c054dd598149819800981c80098188008b180c9980e000919808980a9bab30273031001006323301c0012323253330353370e9001000899b8f005375c607460660042940c0cc004c078c0c4c078c0c4004dd6180c9817980e18178149bae3035001302d001163019302c3019302c3022302c005375c606400260540022c600c601a00260166eacc078c0a0c078c0a0004c0b8004c09800458cc00cdd6180918129809181280f80b8a999813998021809181280f9bac30013025021133300601f02402214a0294054ccc09cc8c8c8c8c8c8c8c8c94ccc0c0cdc3a4000605e002264646464a66606866e1d20003033001132323232533303b303e00213253330393370e6038603600e9001099b87001480045281bad303a00116303c00132323253330393370e90010008a5eb7bdb1804dd5981f181b801181b800998118008011980f80424500375c607400260640022c601c602a00260266eacc098c0c0c098c0c0004c0d8004c0b800458cc02cdd6180d1816980d181681380f9bab303300130330013032001303100130300013027001302d001302501f1533302733300601f0240221330043012302501f37586002604a042294052811816181698169816800929998148008a60103d87a800013374a9000198151815800a5eb8088c8cc00400400c894ccc0ac0045300103d87a800013232533302a3375e602a605000400a266e9520003302e0024bd7009980200200098178011816800911919198008008019129998158008a5013232533302a3300800500214a2266008008002605e0046eb8c0b4004dd618151815981598159815981598159815981598118011119198008008019129998148008a501323253330283371e00400a29444cc010010004c0b4008dd718158009111919299981319b8748000c0940044c8c94ccc0a0cdc39806802240042a66605066e1cc02cc028c024dd5980e1813000a4000266e24014c020dd5980e18130008a5014a0605800260480022c6018002646601e002466ebcc044c090c044c090004010dd618061811180798110019191919299981219b8748008004520001375a60526044004604400264a66604666e1d200200114c103d87a8000132323300100100222533302900114c103d87a8000132323232533302a3371e9110000213374a9000198171ba80014bd700998030030019bad302b003375c6052004605a00460560026eacc0a0c084008c084004cc034005220100233009001489002300c00130010012253330210011480004cdc024004660040046048002600200244a66603e00229000099b8048008cc008008c08800494ccc0740045300103d87a800013374a90001980f180f800a5eb808c078c07cc07c00488c8cc00400400c894ccc07800452f5bded8c0264646464a66603e66e3c01c008400c4cc08ccdd81ba9002374c0026600c00c0066eacc08000cdd7180f0011811001181000091191980080080191299980e8008a5eb804c8c94ccc070c0140084cc080008cc0100100044cc010010004c084008c07c0048c06c00488c8cc00400400c894ccc06c0045300103d87a8000132323232533301c3371e00e004266e95200033020374c00297ae01330060060033756603a0066eb8c06c008c07c008c074004c004004894ccc05c00452f5c0266030602a60320026600400460340026020014602a002601a0042940c034004c004c02c0148c048c04c0045261365632533300c3370e90000008a99980798050028a4c2c2a66601866e1d20020011533300f300a00514985858c028010c0040108c94ccc02ccdc3a400000226464646464646464a66602c603200426493191980080080111299980c0008a4c2646600600660380046eb8c06800458dd6180b800980b8011bae30150013015002375c602600260260046eb4c044004c02400858c024004dd6800918029baa001230033754002ae6955ceaab9e5573eae815d0aba201',
hash: 'bb6c9914e0352a1770659aedbafd69c148c6ecf0e1a0835e6f3cd820'
},
{
title: 'singleton.singleton_mint_and_burn',
Expand All @@ -68,8 +68,8 @@ export const PLUTUSJSON: PlutusJson = {
}
],
compiledCode:
'5902e8010000323232323232323232323223222232533300a32323232533300e3370e9000180600089919191919191919191919299980e98100010991919299980e19b874800000454ccc070c8cc004004030894ccc08800452809919299981019baf3026301d00201a14a2266008008002604c00460480022a66603866e1c009200213371e00602e294054cc0752401254578706563746564206f6e20696e636f727265637420426f6f6c65616e2076617269616e7400161533301c3370e0049000899b8f00301714a060320286eb4c074008dd7180d8008a9980d249334c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2065787065637465640016301e001323232533301a3370e90010008a5eb7bdb1804dd59810180b801180b800991980080080111299980f0008a60103d87a8000132323232533301e3371e01e004266e95200033023374c00297ae0133006006003375660400066eb8c078008c088008c080004c8cc004004008894ccc07400452f5bded8c0264646464a66603a66e3d221000021003133022337606ea4008dd3000998030030019bab301f003375c603a0046042004603e0026eacc070004c070004c06c004c068004c064008dd6180b80098068029bae3015001300b001153300f491244578706563746564206f6e20696e636f727265637420436f6e7374722076617269616e7400163013001301300230110013007002149854cc02d2411856616c696461746f722072657475726e65642066616c7365001365632533300a3370e90000008a99980718038018a4c2a660160122c2a66601466e1d20020011533300e3007003149854cc02c0245854cc02d24128436f6e73747220696e646578206469646e2774206d61746368206120747970652076617269616e7400163007002375c0024600e6ea80048c014dd5000a491d4578706563746564206e6f206669656c647320666f7220436f6e737472005734ae7155ceaab9e5573eae815d0aba21',
hash: 'c6c028ed2669c7a23b7298fe1204da33bcbe0611892006377b74d98b'
'5901d901000032323232323232323223222232533300932323232533300d3370e9000180600089919191919191919191919299980d980f0010991919299980d99b874800000454ccc06cc8cc004004030894ccc08000452809919299980f99baf3024301d00201a14a2266008008002604800460440022a66603666e1c009200213371e00602e29405854ccc06ccdc380124002266e3c00c05c528180c80a1bad301b002375c60320022c6038002646464a66603266e1d200200114bd6f7b63009bab301e30170023017001323300100100222533301c00114c103d87a8000132323232533301d3371e01e004266e95200033021374c00297ae01330060060033756603c0066eb8c070008c080008c078004c8cc004004008894ccc06c00452f5bded8c0264646464a66603866e3d221000021003133020337606ea4008dd3000998030030019bab301d003375c6036004603e004603a0026eacc068004c068004c064004c060004c05c008dd6180a80098068029bae3013001300b0011630110013011002300f001300700214984d958c94ccc024cdc3a40000022a666018600e0062930b0a99980499b874800800454ccc030c01c00c52616163007002375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae89',
hash: '81cbb6417e3213bc9006a2647a82a45fad19bd379a8a44121587faca'
}
],
definitions: {
Expand Down
2 changes: 1 addition & 1 deletion tests/events.multi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('Singleton mint should work', async () => {
});

test('Event recreation with multiple inputs sharing common signers should work', async () => {
const completeTx = await winterEvent1.recreate(walletAddress1, sharedUtxos);
const completeTx = await winterEvent1.recreate(walletAddress1, sharedUtxos, ["deafbeef", "cafebabe"]);
const signedTx = await completeTx.sign().complete();
const txHash = await signedTx.submit();
await winterEvent1.waitForTx(txHash);
Expand Down
18 changes: 16 additions & 2 deletions tests/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('Singleton mint should work', async () => {
});

test('Event recreation should work', async () => {
const completeTx = await winterEvent.recreate(walletAddress, sharedUtxos);
const completeTx = await winterEvent.recreate(walletAddress, sharedUtxos, ['deadbeef']);
const signedTx = await completeTx.sign().complete();
const txHash = await signedTx.submit();
await winterEvent.waitForTx(txHash);
Expand All @@ -66,8 +66,22 @@ test('Event recreation should work', async () => {
});

test('Event recreation should work repeatedly', async () => {
const uniqueHexStrings = [
'link1',
'link2',
'link3',
'link4',
'link5',
'link6',
'link7',
'link8',
'link9',
'link10'
].map(fromText);
for (let i = 0; i < 10; i++) {
const completeTx = await winterEvent.recreate(walletAddress, sharedUtxos);
const completeTx = await winterEvent.recreate(walletAddress, sharedUtxos, [
uniqueHexStrings[i]
]);
const signedTx = await completeTx.sign().complete();
const txHash = await signedTx.submit();
await winterEvent.waitForTx(txHash);
Expand Down

0 comments on commit a1431d6

Please sign in to comment.