aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
474 stars 92 forks source link

multi signature wallet contract #1035

Closed avi69night closed 1 week ago

avi69night commented 1 week ago

Multi-signature_Wallet_Contract.ak

Experimental code is ---

. . . contract MultiSigWallet { entrypoint approve(tx: Tx, signers: List, required_signatures: Int) -> Bool { let valid_signatures = signers.filter(|sig| tx.is_signed_by(sig)) valid_signatures.length() >= required_signatures } }

. . .

Issues

The issue with the code you provided lies in the use ofv .length()and the implicit return type.

  1. .length() : The Aiken language might not have a length() function for lists. Instead, It needs to use the size function to get the number of elements in a list.

Implicit Return: In Aiken-lang, need to explicitly return the result of the final expression in the function.

avi69night commented 1 week ago

The Right Code is

. . .

contract MultiSigWallet { entrypoint approve(tx: Tx, signers: List, required_signatures: Int) -> Bool { let valid_signatures = signers.filter(|sig| tx.is_signed_by(sig)) valid_signatures.size() >= required_signatures } }

. . .

Changes: Replaced .length() with.size()to get the size of the list. The final expression will implicitly return the comparison result (valid_signatures.size() >= required_signatures).