mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-12-22 03:57:31 +01:00
Add sweep function
This commit is contained in:
parent
75c16b7198
commit
f9cd542e74
@ -1,3 +1,5 @@
|
||||
- 0.3.7
|
||||
* Add sweep contract method to fully empty one account into another
|
||||
- 0.3.6
|
||||
* Reinstate owner as minter by default
|
||||
- 0.3.0
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -443,6 +443,19 @@ class DemurrageToken(ERC20, SealedContract, ExpiryContract):
|
||||
return tx
|
||||
|
||||
|
||||
def sweep(self, contract_address, sender_address, recipient_address, tx_format=TxFormat.JSONRPC):
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('sweep')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(recipient_address)
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
|
||||
def apply_demurrage(self, contract_address, sender_address, limit=0, tx_format=TxFormat.JSONRPC):
|
||||
if limit == 0:
|
||||
return self.transact_noarg('applyDemurrage', contract_address, sender_address)
|
||||
@ -474,8 +487,6 @@ class DemurrageToken(ERC20, SealedContract, ExpiryContract):
|
||||
return tx
|
||||
|
||||
|
||||
|
||||
|
||||
def tax_level(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||
return self.call_noarg('taxLevel', contract_address, sender_address=sender_address)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = erc20-demurrage-token
|
||||
version = 0.3.6
|
||||
version = 0.3.7
|
||||
description = ERC20 token with redistributed continual demurrage
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -122,5 +122,26 @@ class TestAmounts(TestDemurrageDefault):
|
||||
self.assert_within_lower(balance, case[1], 10000)
|
||||
|
||||
|
||||
def test_sweep(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], 2000)
|
||||
r = self.rpc.do(o)
|
||||
|
||||
(tx_hash, o) = c.sweep(self.address, self.accounts[0], self.accounts[1])
|
||||
self.rpc.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(c.parse_balance(r), 0)
|
||||
|
||||
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
self.assert_within(c.parse_balance(r), 2000, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -292,6 +292,16 @@ contract DemurrageTokenSingleNocap {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send full balance of one account to another
|
||||
function sweep(address _account) public returns (uint256) {
|
||||
uint256 v;
|
||||
|
||||
v = account[msg.sender];
|
||||
account[msg.sender] = 0;
|
||||
account[_account] += v;
|
||||
return v;
|
||||
}
|
||||
|
||||
// Creates new tokens out of thin air, and allocates them to the given address
|
||||
// Triggers tax
|
||||
function mintTo(address _beneficiary, uint256 _amount) external returns (bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user