MyLegacy

MyLegacy

* By Starcoin Community

Struct Definition

struct Legacy has key, store { payer: address, payee: address, total_value:u64, times:u64, freq:u64, unpaid: vector<Payment>, }
struct Payment has key, store { id: u64, value: u64, balance: Token<STC>, time_lock: u64, }
  • We do not need to worry about losing money during transactions as Legacy and Payment cannot be dropped.
  • You cannot do unsecure money creation because Legacy and Payment cannot be copied from one instance to a new instance.
  • Legacy or Payment is a whole, can only be modified by functions in this contract, other contracts can only store.

Function Definition

public(script) fun init_legacy(account: signer, payee: address, total_value: u64, times: u64, freq: u64)
  • Script Visibility: This function cannot be accessed by other functions, it’s only one transaction.
  • No return values
  • payee: The address you are used to redeem STC.
  • total_value: Total STC
  • times: Current number of payments
  • Number of STC in each payment: total_value / times
  • freq: Interval between payments in freq seconds.
public(script) fun redeem(account: signer, payer: address) acquires Legacy
  • Script Visibility: This function cannot be accessed by other functions, it’s only one transaction.
  • No return values
  • payer: Can be default address who create Legacy, and also can be the address you pass into when you construct Legacy.
  • acquires: This is the struct you should define and use in current contract, here is Legacy
  • How many payments can you redeem: (current time — last redeem time) / freq, the last redeem time is the time you construct Legacy if this is your first to do redeem

Retrospective

  • Data is distributed and stored in the initial Legacy user account, there is no big array problem.
  • You cannot drop and copy Payment or Legacy, so it’s secure.
  • Function visibility, only init_legacy and redeem are exposed.
  • Full functionality.
  • To support any type Token by generic programming, to make a general protocol.
  • To support formal verification, use mathematical method to prove this contract is secure
  • To clean out Legacy that does not have payment when do redeem
  • One account can only have one legacy
  • Data redundancy, times and freq are equal to 0

Conclusion

--

--

Starcoin is a proof-of-work blockchain that enables secure smart contracts based on Move to power services in Web 3.0

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Starcoin

Starcoin is a proof-of-work blockchain that enables secure smart contracts based on Move to power services in Web 3.0