MCPcopy Create free account
hub / github.com/DNAProject/DNA / approve

Function approve

wasmtest/contracts-cplus/test_oep4.py:196–219  ·  view source on GitHub ↗

owner allow spender to spend amount of token from owner account Note here, the amount should be less than the balance of owner right now. :param owner: :param spender: :param amount: amount>=0 :return: True means success, False or raising exception means failure.

(owner,spender,amount)

Source from the content-addressed store, hash-verified

194
195
196def approve(owner,spender,amount):
197 """
198 owner allow spender to spend amount of token from owner account
199 Note here, the amount should be less than the balance of owner right now.
200 :param owner:
201 :param spender:
202 :param amount: amount>=0
203 :return: True means success, False or raising exception means failure.
204 """
205 if len(spender) != 20 or len(owner) != 20:
206 raise Exception("address length error")
207 if CheckWitness(owner) == False:
208 return False
209 if amount > balanceOf(owner) or amount < 0:
210 return False
211
212 key = concat(concat(APPROVE_PREFIX,owner),spender)
213 Put(ctx, key, amount)
214
215 # Notify(["approval", AddressToBase58(owner), AddressToBase58(spender), amount])
216 # ApprovalEvent(AddressToBase58(owner), AddressToBase58(spender), amount)
217 ApprovalEvent(owner, spender, amount)
218
219 return True
220
221
222def transferFrom(spender,from_acct,to_acct,amount):

Callers 3

MainFunction · 0.70
test_native_ontMethod · 0.70
invokeFunction · 0.50

Calls 1

balanceOfFunction · 0.85

Tested by

no test coverage detected