@@ -5,7 +5,7 @@ import akka.util.Timeout
5
5
import encry .EncryApp ._
6
6
import encry .cli .{Ast , Response }
7
7
import encry .modifiers .mempool .{Transaction , TransactionFactory }
8
- import encry .modifiers .state .box .{ AssetBox , EncryProposition }
8
+ import encry .modifiers .state .box .AssetBox
9
9
import encry .settings .EncryAppSettings
10
10
import encry .view .EncryNodeViewHolder .ReceivableMessages ._
11
11
import encry .view .history .EncryHistory
@@ -16,38 +16,38 @@ import org.encryfoundation.common.transaction.EncryAddress.Address
16
16
import scala .concurrent .Future
17
17
import scala .util .Try
18
18
19
- // TODO: Fix me
20
- // object Transfer extends Command {
21
- //
22
- // /**
23
- // * Command "wallet transfer -addr=<addr[String]> -fee=<fee[Num]> -amount=<amount[Num]> "
24
- // * Example "wallet transfer -addr='3jSD9fwHEHJwHq99ARqhnNhqGXeKnkJMyX4FZjHV6L3PjbCmjG' -fee=10000 -amount=2000"
25
- // */
26
- // override def execute(args: Command.Args, settings: EncryAppSettings): Future[Option[Response]] = {
27
- // implicit val timeout: Timeout = Timeout(settings.restApi.timeout)
28
- // (nodeViewHolder ?
29
- // GetDataFromCurrentView[EncryHistory, UtxoState, EncryWallet, Mempool, Option[Transaction]] { view =>
30
- // Try {
31
- // val secret: PrivateKey25519 = view.vault.accountManager.mandatoryAccount
32
- // val recipient: Address = args.requireArg[Ast.Str ]("addr ").s
33
- // val fee : Long = args.requireArg[Ast.Num]("fee ").i
34
- // val amount: Long = args.requireArg[Ast.Num]("amount").i
35
- // val boxes: IndexedSeq [AssetBox] = view.vault.walletStorage.allBoxes.filter(_.isInstanceOf [AssetBox])
36
- // .map(_.asInstanceOf[AssetBox]).foldLeft(Seq[AssetBox]( )) { case ( seq, box) =>
37
- // if (seq.map(_.amount).sum < (amount + fee)) seq :+ box else seq
38
- // }.toIndexedSeq
39
- // TransactionFactory.defaultPaymentTransactionScratch(secret, fee, 0L, boxes, recipient, amount)
40
- // }.toOption
41
- // }).flatMap {
42
- // case Some(tx: Transaction) =>
43
- // timeProvider
44
- // .time( )
45
- // .map { time =>
46
- // val txWithTimestamp = tx.copy(timestamp = time)
47
- // nodeViewHolder ! LocallyGeneratedTransaction[EncryProposition, Transaction](txWithTimestamp)
48
- // Some(Response(txWithTimestamp.toString) )
49
- // }
50
- // case _ => Future.successful(Some(Response("Operation failed. Malformed data.")))
51
- // }
52
- // }
53
- // }
19
+ object Transfer extends Command {
20
+
21
+ /**
22
+ * Command "wallet transfer -addr=<addr[String]> -fee=<fee[Num]> -amount=<amount[Num]>"
23
+ * Example "wallet transfer -addr='9fRWpnERVQKzR14qN5EGknx8xk11SU6LoZxcJAc53uAv3HRbL4K' -fee=10000 -amount=2000 "
24
+ */
25
+ override def execute ( args : Command . Args , settings : EncryAppSettings ) : Future [ Option [ Response ]] = {
26
+ implicit val timeout : Timeout = Timeout (settings.restApi.timeout)
27
+ (nodeViewHolder ?
28
+ GetDataFromCurrentView [ EncryHistory , UtxoState , EncryWallet , Option [ Transaction ]] { view =>
29
+ Try {
30
+ val secret : PrivateKey25519 = view.vault.accountManager.mandatoryAccount
31
+ val recipient : Address = args.requireArg[ Ast . Str ]( " addr " ).s
32
+ val fee : Long = args.requireArg[Ast .Num ](" fee " ).i
33
+ val amount : Long = args.requireArg[Ast .Num ](" amount " ).i
34
+ val boxes : IndexedSeq [ AssetBox ] = view.vault.walletStorage.getAllBoxes().filter(_. isInstanceOf [ AssetBox ])
35
+ .map(_. asInstanceOf [AssetBox ]).foldLeft( Seq [AssetBox ]()) { case (seq, box) =>
36
+ if (seq .map(_.amount).sum < (amount + fee )) seq :+ box else seq
37
+ }.toIndexedSeq
38
+ TransactionFactory .defaultPaymentTransaction(
39
+ secret,
40
+ fee,
41
+ System .currentTimeMillis(),
42
+ boxes.map(_ -> None ),
43
+ recipient,
44
+ amount )
45
+ }.toOption
46
+ }).flatMap {
47
+ case Some ( tx : Transaction ) =>
48
+ memoryPool ! LocallyGeneratedTransaction (tx )
49
+ Future .successful( Some ( Response (tx.toString)))
50
+ case _ => Future .successful(Some (Response (" Operation failed. Malformed data." )))
51
+ }
52
+ }
53
+ }
0 commit comments