WEP 10: Adding Lease and LeaseCancel structure to RIDE

Author Andrey Andreev [email protected]
Last update 2020-09-30

Abstract

We propose to allow users to lease and cancel lease by means of dApp script. For this purpose we propose to add Lease and LeaseCancel structures to RIDE.

Motivation and Purposes

At the moment, users do not have the ability to use dApp to manage leases.

Withdrawing a leased amount of WAVES without withdrawing it from the generating balance for the next 1000 blocks is possible only if both LeaseCancelTx and the new LeaseTx will get into one (the same) block. Currently it is not possible to control that the two transactions will get into the same block.

To solve this problem and enhance RIDE functionality, we propose to introduce new Lease and LeaseCancel structures into RIDE.

Specification

Lease structure

In RIDE version 5 the structure of WAVES leasing should be supported. This structure should work similarly as LeaseTx.

The structure should have the following signature:

Lease(recipient: Address|Alias, amount: Int)

The structure should have the following arguments:

Argument Type Description
recipient Address/Alias Address or alias of the leasing recipient
amount Int Lease amount

In one script there can be no more than 10 structures of Lease, LeaseCancel, SponsorFee, Issue, Reissue, Burn, Transfer.

When executing the Lease structure, WAVES are leased out from the dApp account.

Using Lease structure does not increase the InvokeScriptTx fee.

Leasing created by the Lease structure is equivalent to leasing obtained through LeaseTx. This lease can be closed the same way as a transaction, but in order to close such lease it is necessary to use the leasing ID, not the leasing transaction ID. The ID of the lease issued through LeaseTx equals to the ID of the transaction, while the ID of the lease issued through Lease structure is formed according to the rule described below.

Calculating Lease ID

The leasing ID must be generated by hashing from the following data:

â„– Name Description
1 InvokeScriptTxId ID InvokeScriptTx
2 recipient Address or alias of the leasing recipient
3 amount Lease amount
4 nonce The number of the lease to be created in this script

LeaseCancel structure

In RIDE version 5 the structure of WAVES leasing should be supported. This structure should work similarly as LeaseTx.

In RIDE version 5 the lease closing structures should be supported. This structure should work similarly as LeaseCancelTx.

The structure should have the following signature:

LeaseCancel(leaseId: ByteVector)

The structure should have the following arguments:

Argument Type Description
leaseId ByteVector ID leasing

In one script there can be no more than 10 structures of Lease, LeaseCancel, SponsorFee, Issue, Reissue, Burn, Transfer.

When executing the LeaseCancel structure, WAVES are leased out from the dApp account.

The LeaseCancel structure can cancel leases issued by Lease structure or LeaseTx transaction. To cancel a lease it is required to use the Lease ID.

The function of calculating the leasing ID created by the Lease structure

In RIDE version 5 the function to calculate the leasing ID created by the Lease structure should be supported.

The function should have the following signature:

calculateLeaseId(lease: Lease): ByteVector

The function should have the following arguments:

Argument Type Description
lease lease Lease structure

The function should form leasing ID from the following arguments:

â„– Name Description
1 InvokeScriptTxId ID InvokeScriptTx
2 recipient Address or alias of the leasing recipient
3 amount Lease amount
4 nonce The number of the lease to be created in this script

Example of using the calculateLeaseId function

{-# STDLIB_VERSION 5 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
 
@Callable
func call() = {
     let lease = Lease(...)
     let id = calculateLeaseId(lease) 
     [
          BinaryEntry("id", id),
          lease
     ]
 }

REST API

The results of Lease and LeaseCancel signature execution will be returned in REST API methods:

  • ​/debug​/stateChanges​/info​/{id}
  • /debug​/stateChanges​/address​/{address}​/limit​/{limit}
  • /transactions/info/{id}
  • /transactions/address/{address}/limit/{limit}

The REST API /leasing/active/{address} method returns an array of active leases with the following data, not LeaseTx array:

â„– Name Type Description
1 leaseId String ID Lease
2 originTransactionId String Lease originating transaction ID
3 sender String Address from which the lease was issued
4 recipient String Lease Receiver
5 amount Int Lease amount
6 height Int Height of leasing issuance
2 Likes