@@ -4,19 +4,14 @@ import com.google.common.base.Charsets
44import com .google .common .collect .AbstractIterator
55import com .wavesplatform .account .{Address , Alias }
66import com .wavesplatform .api .common .AddressPortfolio .{assetBalanceIterator , nftIterator }
7- import com .wavesplatform .api .common .TransactionMeta . Ethereum
7+ import com .wavesplatform .api .common .lease . AddressLeaseInfo
88import com .wavesplatform .common .state .ByteStr
9- import com .wavesplatform .common .utils .EitherExt2
109import com .wavesplatform .database .{DBExt , DBResource , KeyTags , Keys , RDB }
1110import com .wavesplatform .features .BlockchainFeatures
1211import com .wavesplatform .lang .ValidationError
1312import com .wavesplatform .protobuf .transaction .PBRecipients
14- import com .wavesplatform .state .LeaseDetails .Status
15- import com .wavesplatform .state .{AccountScriptInfo , AssetDescription , Blockchain , DataEntry , Height , InvokeScriptResult , SnapshotBlockchain , TxMeta }
13+ import com .wavesplatform .state .{AccountScriptInfo , AssetDescription , Blockchain , DataEntry , SnapshotBlockchain }
1614import com .wavesplatform .transaction .Asset .IssuedAsset
17- import com .wavesplatform .transaction .EthereumTransaction .Invocation
18- import com .wavesplatform .transaction .lease .LeaseTransaction
19- import com .wavesplatform .transaction .{EthereumTransaction , TransactionType }
2015import monix .eval .Task
2116import monix .reactive .Observable
2217
@@ -127,75 +122,13 @@ object CommonAccountsApi {
127122 override def resolveAlias (alias : Alias ): Either [ValidationError , Address ] = blockchain.resolveAlias(alias)
128123
129124 override def activeLeases (address : Address ): Observable [LeaseInfo ] =
130- addressTransactions(
131- rdb,
132- Some (Height (blockchain.height) -> compositeBlockchain().snapshot),
133- address,
134- None ,
135- Set (TransactionType .Lease , TransactionType .InvokeScript , TransactionType .InvokeExpression , TransactionType .Ethereum ),
136- None
137- ).flatMapIterable {
138- case TransactionMeta (leaseHeight, lt : LeaseTransaction , TxMeta .Status .Succeeded ) if leaseIsActive(lt.id()) =>
139- Seq (
140- LeaseInfo (
141- lt.id(),
142- lt.id(),
143- lt.sender.toAddress,
144- blockchain.resolveAlias(lt.recipient).explicitGet(),
145- lt.amount.value,
146- leaseHeight,
147- LeaseInfo .Status .Active
148- )
149- )
150- case TransactionMeta .Invoke (invokeHeight, originTransaction, TxMeta .Status .Succeeded , _, Some (scriptResult)) =>
151- extractLeases(address, scriptResult, originTransaction.id(), invokeHeight)
152- case Ethereum (height, tx @ EthereumTransaction (_ : Invocation , _, _, _), TxMeta .Status .Succeeded , _, _, Some (scriptResult)) =>
153- extractLeases(address, scriptResult, tx.id(), height)
154- case _ => Seq ()
155- }
156-
157- private def extractLeases (subject : Address , result : InvokeScriptResult , txId : ByteStr , height : Height ): Seq [LeaseInfo ] = {
158- (for {
159- lease <- result.leases
160- details <- blockchain.leaseDetails(lease.id) if details.isActive
161- sender = details.sender.toAddress
162- recipient <- blockchain.resolveAlias(lease.recipient).toOption if subject == sender || subject == recipient
163- } yield LeaseInfo (
164- lease.id,
165- txId,
166- sender,
167- recipient,
168- lease.amount,
169- height,
170- LeaseInfo .Status .Active
171- )) ++ {
172- result.invokes.flatMap(i => extractLeases(subject, i.stateChanges, txId, height))
173- }
174- }
175-
176- def leaseInfo (leaseId : ByteStr ): Option [LeaseInfo ] = blockchain.leaseDetails(leaseId) map { ld =>
177- LeaseInfo (
178- leaseId,
179- ld.sourceId,
180- ld.sender.toAddress,
181- ld.recipientAddress,
182- ld.amount.value,
183- ld.height,
184- ld.status match {
185- case Status .Active => LeaseInfo .Status .Active
186- case Status .Cancelled (_, _) => LeaseInfo .Status .Canceled
187- case Status .Expired (_) => LeaseInfo .Status .Expired
188- },
189- ld.status.cancelHeight,
190- ld.status.cancelTransactionId
191- )
192- }
125+ AddressLeaseInfo .activeLeases(rdb, compositeBlockchain().snapshot, address)
193126
194- private [ this ] def leaseIsActive ( id : ByteStr ): Boolean =
195- blockchain.leaseDetails(id).exists(_.isActive )
127+ def leaseInfo ( leaseId : ByteStr ): Option [ LeaseInfo ] =
128+ blockchain.leaseDetails(leaseId).map( LeaseInfo .fromLeaseDetails(leaseId, _) )
196129 }
197130
198- class AddressDataIterator (
131+ private class AddressDataIterator (
199132 db : DBResource ,
200133 address : Address ,
201134 entriesFromDiff : Array [DataEntry [? ]],
0 commit comments