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)
| 194 | |
| 195 | |
| 196 | def 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 | |
| 222 | def transferFrom(spender,from_acct,to_acct,amount): |
no test coverage detected