-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Fix macros, fix tests, fix examples, fix clippy lints, new and impro…
…ved error handling, reduce allocations"
- Loading branch information
1 parent
496a7a3
commit fd47c36
Showing
14 changed files
with
570 additions
and
607 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"configurations": { | ||
"<name>: Launch": { | ||
"adapter": "CodeLLDB", | ||
"configuration": { | ||
"name": "<name>", | ||
"type": "lldb", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/target/debug/deps/vyper_rs-686403a730734cd8", | ||
"cwd": "${workspaceRoot}", | ||
"externalConsole": true, | ||
"stopAtEntry": true, | ||
"MIMode": "gdb" | ||
} | ||
}, | ||
"<name>: Attach": { | ||
"adapter": "CodeLLDB", | ||
"configuration": { | ||
"name": "<name>: Attach", | ||
"type": "lldb", | ||
"request": "attach", | ||
"program": "${workspaceRoot}/target/debug/deps/vyper_rs-686403a730734cd8", | ||
"MIMode": "gdb" | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
use std::{error::Error, path::PathBuf}; | ||
use vyper_rs::{venv::Venv, vyper::Vyper}; | ||
use std::{error::Error, path::Path}; | ||
use vyper_rs::venv::Venv; | ||
|
||
pub fn venv_example() -> Result<(), Box<dyn Error>> { | ||
let cpath: PathBuf = PathBuf::from("../../multisig.vy"); | ||
let abi: PathBuf = PathBuf::from("./my_abi.json"); | ||
let venv = Venv::new().init()?.ivyper_venv(None)?; | ||
let mut contract = Vyper::new(cpath, abi); | ||
venv.compile(&mut contract)?; | ||
let mut contract = Venv::default() | ||
.init()? | ||
.ivyper_venv(None)? | ||
.vyper(Path::new("../../multisig.vy")); | ||
contract.compile()?; | ||
Ok(()) | ||
} |
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,125 @@ | ||
# @version ^0.3.3 | ||
# Multiple Signature Contract | ||
|
||
event Deposit: | ||
sender: indexed(address) | ||
amount: uint256 | ||
bal: uint256 | ||
event SubmitTransaction: | ||
owner: indexed(address) | ||
txIndex: indexed(uint256) | ||
to: indexed(address) | ||
value: uint256 | ||
data: bytes32 | ||
event ConfirmTransaction: | ||
owner: indexed(address) | ||
txIndex: indexed(uint256) | ||
event RevokeConfirmation: | ||
owner: indexed(address) | ||
txIndex: indexed(uint256) | ||
event ExecuteTransaction: | ||
owner: indexed(address) | ||
txIndex: indexed(uint256) | ||
|
||
owners: DynArray[address, 10] | ||
isOwner: HashMap[address, bool] | ||
numConfirmationsRequired: constant(uint256) = 1 | ||
|
||
|
||
struct Transaction: | ||
to: address | ||
val: uint256 | ||
data: bytes32 | ||
fnSel: String[32] | ||
executed: bool | ||
numConfirmations: uint256 | ||
|
||
|
||
isConfirmed: public(HashMap[uint256, HashMap[address, bool]]) | ||
|
||
transactions: DynArray[Transaction, 100000] | ||
|
||
|
||
@external | ||
def __init__ (_owners: DynArray[address,10]): | ||
assert len(_owners) > 0, "Error: No Owners" | ||
assert numConfirmationsRequired > 0 and numConfirmationsRequired <= len(_owners) | ||
for o in _owners: | ||
assert o != empty(address) | ||
assert self.isOwner[o] == False, "Owner Not Unique" | ||
self.isOwner[o] = True | ||
self.owners.append(o) | ||
|
||
@external | ||
@payable | ||
def __default__(): | ||
log Deposit(msg.sender, msg.value, self.balance) | ||
|
||
@external | ||
def submitTransaction( _to: address, _val: uint256, _data: bytes32, _fnSel: String[32]): | ||
assert self.isOwner[msg.sender] == True, "Not an Owner" | ||
txIndex: uint256 = len(self.transactions) | ||
self.transactions.append(Transaction({to:_to, val:_val, data: _data, fnSel: _fnSel, executed: False, numConfirmations: 0})) | ||
|
||
@external | ||
def confirmTransaction(txIndex: uint256): | ||
assert self.isOwner[msg.sender]==True, "Not an Owner" | ||
assert txIndex < len(self.transactions), "Does Not Exist" | ||
assert self.transactions[txIndex].executed == False, "Transaction Already Executed" | ||
assert self.isConfirmed[txIndex][msg.sender], "Transactions Already Confirmed" | ||
self.transactions[txIndex].numConfirmations += 1 | ||
self.isConfirmed[txIndex][msg.sender] = True | ||
log ConfirmTransaction(msg.sender, txIndex) | ||
|
||
@payable | ||
@external | ||
def executeTransaction(txIndex: uint256) -> Bytes[32]: | ||
assert self.isOwner[msg.sender]==True, "Not an Owner" | ||
assert txIndex < len(self.transactions), "Does Not Exist" | ||
assert self.transactions[txIndex].executed == False, "Transaction Already Executed" | ||
assert self.transactions[txIndex].numConfirmations >= numConfirmationsRequired, "Insufficent Confirmations" | ||
self.transactions[txIndex].executed = True | ||
success: bool = False | ||
response: Bytes[32] = b"" | ||
functionSelector: Bytes[32] = convert(self.transactions[txIndex].fnSel, Bytes[32]) | ||
success, response = raw_call( | ||
self.transactions[txIndex].to, | ||
#add field for function selector, seperate from data | ||
_abi_encode(self.transactions[txIndex].data, (convert(keccak256(self.transactions[txIndex].fnSel), bytes4))), | ||
max_outsize=32, | ||
value = self.transactions[txIndex].val, | ||
revert_on_failure = False | ||
) | ||
assert success | ||
return response | ||
|
||
@nonpayable | ||
@external | ||
def revokeConfirmation(_txIndex: uint256): | ||
assert _txIndex < len(self.transactions), "Does Not Exist" | ||
assert self.transactions[_txIndex].executed == False, "Transaction Already Executed" | ||
self.transactions[_txIndex].numConfirmations -= 1 | ||
self.isConfirmed[_txIndex][msg.sender] = False | ||
log RevokeConfirmation(msg.sender, _txIndex) | ||
|
||
@view | ||
@external | ||
def getOwners() -> DynArray[address, 10]: | ||
return self.owners | ||
|
||
@view | ||
@external | ||
def getTransactionCount() -> uint256: | ||
return len(self.transactions) | ||
|
||
@view | ||
@external | ||
def getTransaction(_txIndex: uint256) -> (address, uint256, bytes32, String[32], bool, uint256): | ||
return( | ||
self.transactions[_txIndex].to, | ||
self.transactions[_txIndex].val, | ||
self.transactions[_txIndex].data, | ||
self.transactions[_txIndex].fnSel, | ||
self.transactions[_txIndex].executed, | ||
self.transactions[_txIndex].numConfirmations | ||
) |
Oops, something went wrong.