Hi Folks,
As part of my learning process of the Move language. I am trying to come up with a simple loan contract that is inspired from the documentation on the libra website. However, i have run into some issues.
This is the module where i plan to include basic procedures:
// SI Module
address 0xc0fce77edef949b6fa9f0ad0c35be2c4 {
module SimpleInterest {
resource struct Interest<CoinType> {
interest: u64
}
// Set the interest rate
public fun set_interest<CoinType>(account: &signer, interest: u64) {
move_to(account, Interest<CoinType> { interest })
}
public fun update_rate<CoinType>(account: address, new_interest: u64): u64 acquires Interest {
let intr = borrow_global_mut<Interest<CoinType>>(account);
intr.interest = new_interest;
intr.interest
}
// Destroy the resource
//public fun destroy_interest<CoinType>(account: &signer, interest: u64){
// let intr = move_from<Interest<u64>>(account);
//let Interest { interest: _ } = intr ;
//}
// Get the interest rate for the loan.
public fun get_interest<CoinType>(account: address): u64 acquires Interest {
if (exists<Interest<CoinType>>(account))
borrow_global<Interest<CoinType>>(account).interest
else
0
}
}
}
This is the transaction script for updating the interest rate
$ cat update_interest.move
script {
use 0x1::LBR::LBR;
use 0xc0fce77edef949b6fa9f0ad0c35be2c4::SimpleInterest;
fun update_rate(lender: address, new_rate: u64): u64
{ SimpleInterest::update_rate<LBR>(lender, new_rate) }
}
When i compile the update_interest.move
, the following error occurs:
libra% dev compile 0 /home/faizancloudcomputing/update_interest.move /home/faizancloudcomputing/SimpleInterest.move /home/faizancloudcomputing/libra/language/stdlib/modules
>> Compiling program
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
Running `target/debug/move-build /home/faizancloudcomputing/update_interest.move -s c0fce77edef949b6fa9f0ad0c35be2c4 -o /tmp/06796a3d4b54eec4784b87310281a04c -d /home/faizancloudcomputing/SimpleInterest.move -d /home/faizancloudcomputing/libra/language/stdlib/modules`
error:
┌── /home/faizancloudcomputing/update_interest.move:7:5 ───
│
7 │ fun update_rate(lender: address, new_rate: u64): u64
│ ^^^^^^^^^^^ Invalid main return type
·
7 │ fun update_rate(lender: address, new_rate: u64): u64
│ --- The type: 'u64'
·
7 │ fun update_rate(lender: address, new_rate: u64): u64
│ ----------- Is not compatible with: '()'
│
compilation failed
I was wondering whether the return type should be u64 or something else? Also, is it possible to have if statements that would execute some logic based on the time period?
Thanks in advance!
Best regards,
Syed