Skip to content

Commit

Permalink
Merge pull request #2 from Lunes-platform/attachment
Browse files Browse the repository at this point in the history
Version 0.0.5 : Mainnet signature.
  • Loading branch information
marcoslkz committed Jun 5, 2018
2 parents 497f582 + eb14465 commit ced30ea
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 186 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -5,7 +5,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject

enablePlugins(GitVersioning)
git.useGitDescribe := true
git.baseVersion := "0.0.4"
git.baseVersion := "0.0.5"
name := "LunesNode"
mainClass in Compile := Some("io.lunes.LunesNode")

Expand Down
48 changes: 11 additions & 37 deletions lunes.conf
@@ -1,62 +1,36 @@
# Lunes node settings
lunes {
directory = "LUNES"
blockchain.type = MAINNET

network {
known-peers = ["35.190.160.211:5550"]

# Network address
known-peers = ["52.6.200.147:7770", "54.164.234.204:7770"]
# declared-address = "127.0.0.1:7770"
bind-address = "0.0.0.0"

# Port number
port = 5550
port = 7770
}

# Wallet settings
wallet {
# Password to protect wallet file
password = "LunesNode"

# Wallet seed as BASE58 string
# seed = ""
password = "LocalPasswordWallet"
seed = ""
}


# Node's REST API settings
rest-api {
# Enable/disable node's REST API
enable = yes

# Network address to bind to
bind-address = "0.0.0.0"

# Port to listen to REST API requests
bind-address = "127.0.0.1"
port = 5555

# Hash of API key string: "lunes_apikey"
# api-key-hash = ""
# api-key-hash = "
}

upnp {
enable = yes
enable = no
gateway-timeout = 47s
discover-timeout = 43s
}

miner {
# Enable/disable block generation
enable = no

# Required number of connections (both incoming and outgoing) to attempt block generation. Setting this value to 0
# enables "offline generation".
enable = yes
quorum = 1

# Enable block generation only in the last block is not older the given period of time
interval-after-last-block-then-generation-is-allowed = 111d
interval-after-last-block-then-generation-is-allowed = 1d
}

features {
supported = [2] # NG
}
}

2 changes: 1 addition & 1 deletion src/main/scala/io/lunes/features/BlockchainFeature.scala
Expand Up @@ -15,6 +15,6 @@ object BlockchainFeatures {
val MassTransfer = BlockchainFeature(3)
val SmartAccounts = BlockchainFeature(4)

val implemented: Set[Short] = Set(NG, MassTransfer).map(_.id)
val implemented: Set[Short] = Set(NG).map(_.id)
val preActivated: Map[Short, Int] = Set(NG).map(_.id).map{case (v: Short) => (v,v.toInt)}.toMap
}
2 changes: 0 additions & 2 deletions src/main/scala/io/lunes/settings/BlockchainSettings.scala
Expand Up @@ -5,10 +5,8 @@ import io.lunes.state2.ByteStr
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import net.ceedubs.ficus.readers.EnumerationReader._

import scala.concurrent.duration._

import io.lunes.features.BlockchainFeatures

/**
*
Expand Down
31 changes: 14 additions & 17 deletions src/main/scala/io/lunes/settings/Constants.scala
Expand Up @@ -9,33 +9,30 @@ import scorex.utils.ScorexLogging
*
*/
object Constants extends ScorexLogging {
val VersionStr = "0.0.4"
val VersionTuple = (0, 0, 4)
val MinimalVersion = (0, 0, 4)
val VersionStr = "0.0.5"
val VersionTuple = (0, 0, 5)
val MinimalVersion = (0, 0, 5)
val ApplicationName = "lunesnode"
val CoinName = "LUNES"
val CoinAbr = "LNS"
val AgentName = s"Lunes v${VersionStr}"
val UnitsInLunes = 100000000L
val TotalLunes = 600000000L
val InitialBalance = TotalLunes * UnitsInLunes
val AgentName = s"lunesnode"
val InitialBalance = 15072853761500800L

val MainSchemeCharacter = '0'
val MainSchemeCharacter = '1'
val MainDelay = 60
val MainTimestamp = 1523145600000L
val MainSignature = "5UoT695i3nk3nd553QtRCkmWzRpyQ8oQNCn4Kdrrs6uN6gJKo8LLNskAiYeqYnxdipPfhXXNQkyKaKAA83dwqGqg"
val MainTimestamp = 1528077600000L
val MainSignature = "soKTPcsb5cD97jnm64zF3pVuVUqUYx3caaDvuPyM6PXPY7eWCxeHeYvKSE2aJwZwRpXdRFdW1g5BQMFpYkHcf85"

val MainTransactions = List(
GenesisTransactionSettings("37cjwk5WavHeoCjNUi92vba6KsNAd1uwAso", 30000000000000000L),
GenesisTransactionSettings("37SGwubdwB1T8ri2Wh6XwcfkzhisqoLH45g", 20000000000000000L),
GenesisTransactionSettings("37cpimjxZ7kQ4akeq2pAB3rVi2eoXaze2sJ", 10000000000000000L)
GenesisTransactionSettings("37oqFHsx1cRtLWtnp6YyQpud5WJk4v79VPu", 5072853761500800L),
GenesisTransactionSettings("3826zwbgHauHXAoppU4we3hsJc9GtRCpSvz", 10000000000000000L),
)

val TestSchemeCharacter = '1'
val TestSchemeCharacter = '0'
val TestDelay = 60
val TestTimestamp = 1522368000000L
val TestSignature = "TwtrT2Q7zNNTsGSdVjZkpb3YzGBExqCuhUY4HFrFQZrQ5ZGNPKRn25QGaywgBfxVvUn132C5w5GoNf8SBA1bGsk"
val TestInitialBalance = TotalLunes * UnitsInLunes
val TestTimestamp = 1523145600000L
val TestSignature = ""

val TestTransactions = List(
GenesisTransactionSettings("3825YjBosdU7g2AWZjZNF5hN7VsRZg35RcA", 30000000000000000L),
GenesisTransactionSettings("37qcYthwDtBv1g9AbiWsG6o2nLE8nXxF2vr", 30000000000000000L)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/io/lunes/state2/StateStorage.scala
Expand Up @@ -7,7 +7,6 @@ import io.lunes.db._
import io.lunes.utils._
import org.iq80.leveldb.{DB, WriteBatch}
import scorex.account.{Address, Alias}
import scorex.serialization.Deser
import scorex.utils.{NTP, Time}

import scala.util.Try
Expand Down
Expand Up @@ -55,7 +55,7 @@ object CommonValidation {
Left(GenericError(s"Attempt to pay unavailable funds: balance " +
s"${s.partialPortfolio(ptx.sender).balance} is less than ${ptx.amount + ptx.fee}"))
case ttx: TransferTransaction => checkTransfer(ttx.sender, ttx.assetId, ttx.amount, ttx.feeAssetId, ttx.fee)
case rdtx: RegistryTransaction => checkTransfer(rdtx.sender, rdtx.assetId, rdtx.amount, rdtx.feeAssetId, rdtx.fee)
case rdtx: RegistryTransaction => checkTransfer(rdtx.sender, None, rdtx.amount, None, rdtx.fee)
case mtx: MassTransferTransaction => checkTransfer(mtx.sender, mtx.assetId, mtx.transfers.map(_.amount).sum, None, mtx.fee)
case _ => Right(tx)
}
Expand Down
29 changes: 4 additions & 25 deletions src/main/scala/io/lunes/state2/diffs/RegistryTransactionDiff.scala
Expand Up @@ -20,31 +20,10 @@ object RegistryTransactionDiff {

val isInvalidEi = for {
recipient <- state.resolveAliasEi(tx.recipient)
portfolios = (
tx.assetId match {
case None => Map(sender -> Portfolio(-tx.amount, LeaseInfo.empty, Map.empty)).combine(
Map(recipient -> Portfolio(tx.amount, LeaseInfo.empty, Map.empty))
)
case Some(aid) =>
Map(sender -> Portfolio(0, LeaseInfo.empty, Map(aid -> -tx.amount))).combine(
Map(recipient -> Portfolio(0, LeaseInfo.empty, Map(aid -> tx.amount)))
)
}).combine(
tx.feeAssetId match {
case None => Map(sender -> Portfolio(-tx.fee, LeaseInfo.empty, Map.empty))
case Some(aid) =>
Map(sender -> Portfolio(0, LeaseInfo.empty, Map(aid -> -tx.fee)))
}
)
assetIssued = tx.assetId match {
case None => true
case Some(aid) => state.assetInfo(aid).isDefined
}
feeAssetIssued = tx.feeAssetId match {
case None => true
case Some(aid) => state.assetInfo(aid).isDefined
}
} yield (portfolios, blockTime > s.allowUnissuedAssetsUntil && !(assetIssued && feeAssetIssued))
portfolios = Map(sender -> Portfolio(-tx.amount, LeaseInfo.empty, Map.empty)).combine( Map(recipient -> Portfolio(tx.amount, LeaseInfo.empty, Map.empty))).combine( Map(sender -> Portfolio(-tx.fee, LeaseInfo.empty, Map.empty)))
assetIssued = true
feeAssetIssued = true
} yield (portfolios, (blockTime > s.allowUnissuedAssetsUntil && !(assetIssued && feeAssetIssued)))

isInvalidEi match {
case Left(e) => Left(e)
Expand Down
13 changes: 3 additions & 10 deletions src/main/scala/io/lunes/transaction/TransactionFactory.scala
Expand Up @@ -27,13 +27,8 @@ object TransactionFactory {
for {
senderPrivateKey <- wallet.findWallet(request.sender)
recipientAcc <- AddressOrAlias.fromString(request.recipient)
tx <- RegistryTransaction
.create(request.assetId.map(s => ByteStr.decodeBase58(s).get),
senderPrivateKey,
recipientAcc,
request.amount,
tx <- RegistryTransaction.create( senderPrivateKey,
request.timestamp.getOrElse(time.getTimestamp()),
request.feeAssetId.map(s => ByteStr.decodeBase58(s).get),
request.fee,
request.userdata.filter(_.nonEmpty).map(Base58.decode(_).get).getOrElse(Array.emptyByteArray))
} yield tx
Expand All @@ -56,8 +51,7 @@ object TransactionFactory {
request.amount,
request.timestamp.getOrElse(time.getTimestamp()),
request.feeAssetId.map(s => ByteStr.decodeBase58(s).get),
request.fee,
request.attachment.filter(_.nonEmpty).map(Base58.decode(_).get).getOrElse(Array.emptyByteArray))
request.fee)
} yield tx

/**
Expand All @@ -77,8 +71,7 @@ object TransactionFactory {
senderPrivateKey,
transfers,
request.timestamp.getOrElse(time.getTimestamp()),
request.fee,
request.attachment.filter(_.nonEmpty).map(Base58.decode(_).get).getOrElse(Array.emptyByteArray))
request.fee)
} yield tx

/**
Expand Down
16 changes: 14 additions & 2 deletions src/main/scala/io/lunes/transaction/Verifier.scala
@@ -1,15 +1,27 @@
package io.lunes.transaction


import io.lunes.crypto
import io.lunes.transaction.ValidationError.GenericError
import io.lunes.state2.reader.SnapshotStateReader

/**
*
*/
object Verifier {

def apply(s: SnapshotStateReader, currentBlockHeight: Int)(tx: Transaction): Either[ValidationError, Transaction] = tx match {
case _: GenesisTransaction => Right(tx)
case stx: SignedTransaction => stx.signaturesValid()
case pt: ProvenTransaction => (pt, None) match {
case (stx: SignedTransaction, None) => stx.signaturesValid()
case _ => verifyAsEllipticCurveSignature(pt)
}
}

def verifyAsEllipticCurveSignature[T <: ProvenTransaction](pt: T): Either[ValidationError, T] =
Either.cond(
crypto.verify(pt.proofs.proofs(0).arr, pt.bodyBytes(), pt.sender.publicKey),
pt,
GenericError(s"proof doesn't validate as signature for $pt"))

}

Expand Up @@ -7,7 +7,6 @@ import io.lunes.state2._
import monix.eval.Coeval
import play.api.libs.json.{Format, JsObject, JsValue, Json}
import scorex.account.{AddressOrAlias, PrivateKeyAccount, PublicKeyAccount}
import scorex.crypto.encode.Base58
import scorex.serialization.Deser
import io.lunes.transaction.TransactionParser._
import io.lunes.transaction.ValidationError.Validation
Expand All @@ -24,7 +23,6 @@ import scala.util.{Either, Failure, Success, Try}
* @param transfers
* @param timestamp
* @param fee
* @param attachment
* @param proofs
*/
case class MassTransferTransaction private(version: Byte,
Expand All @@ -33,7 +31,6 @@ case class MassTransferTransaction private(version: Byte,
transfers: List[ParsedTransfer],
timestamp: Long,
fee: Long,
attachment: Array[Byte],
proofs: Proofs) extends ProvenTransaction with FastHashId {
override val transactionType: TransactionType.Value = TransactionType.MassTransferTransaction

Expand All @@ -53,14 +50,12 @@ case class MassTransferTransaction private(version: Byte,
Shorts.toByteArray(transfers.size.toShort),
transferBytes,
Longs.toByteArray(timestamp),
Longs.toByteArray(fee),
Deser.serializeArray(attachment))
Longs.toByteArray(fee))
}

override def jsonBase(): JsObject = super.jsonBase() ++ Json.obj(
"version" -> version,
"assetId" -> assetId.map(_.base58),
"attachment" -> Base58.encode(attachment),
"transferCount" -> transfers.size,
"totalAmount" -> transfers.map(_.amount).sum)

Expand Down Expand Up @@ -127,7 +122,7 @@ object MassTransferTransaction {
feeAmount = Longs.fromByteArray(bytes.slice(s1 + 8, s1 + 16))
(attachment, attachEnd) = Deser.parseArraySize(bytes, s1 + 16)
proofs <- Proofs.fromBytes(bytes.drop(attachEnd))
mtt <- MassTransferTransaction.create(version, assetIdOpt.map(ByteStr(_)), sender, transfers, timestamp, feeAmount, attachment, proofs)
mtt <- MassTransferTransaction.create(version, assetIdOpt.map(ByteStr(_)), sender, transfers, timestamp, feeAmount, proofs)
} yield mtt
tx.fold(left => Failure(new Exception(left.toString)), right => Success(right))
}.flatten
Expand All @@ -139,7 +134,6 @@ object MassTransferTransaction {
* @param transfers
* @param timestamp
* @param feeAmount
* @param attachment
* @param proofs
* @return
*/
Expand All @@ -149,7 +143,6 @@ object MassTransferTransaction {
transfers: List[ParsedTransfer],
timestamp: Long,
feeAmount: Long,
attachment: Array[Byte],
proofs: Proofs): Either[ValidationError, MassTransferTransaction] = {
Try {
transfers.map(_.amount).fold(feeAmount)(Math.addExact)
Expand All @@ -160,12 +153,10 @@ object MassTransferTransaction {
Left(ValidationError.GenericError(s"Number of transfers is greater than $MaxTransferCount"))
} else if (transfers.exists(_.amount < 0)) {
Left(ValidationError.GenericError("One of the transfers has negative amount"))
} else if (attachment.length > TransferTransaction.MaxAttachmentSize) {
Left(ValidationError.TooBigArray)
} else if (feeAmount <= 0) {
Left(ValidationError.InsufficientFee)
} else {
Right(MassTransferTransaction(version, assetId, sender, transfers, timestamp, feeAmount, attachment, proofs))
Right(MassTransferTransaction(version, assetId, sender, transfers, timestamp, feeAmount, proofs))
}
)
}
Expand All @@ -178,17 +169,16 @@ object MassTransferTransaction {
* @param transfers
* @param timestamp
* @param feeAmount
* @param attachment
* @return
*/
def selfSigned(version: Byte,
assetId: Option[AssetId],
sender: PrivateKeyAccount,
transfers: List[ParsedTransfer],
timestamp: Long,
feeAmount: Long,
attachment: Array[Byte]): Either[ValidationError, MassTransferTransaction] = {
create(version, assetId, sender, transfers, timestamp, feeAmount, attachment, Proofs.empty).right.map { unsigned =>
feeAmount: Long
): Either[ValidationError, MassTransferTransaction] = {
create(version, assetId, sender, transfers, timestamp, feeAmount, Proofs.empty).right.map { unsigned =>
unsigned.copy(proofs = Proofs.create(Seq(ByteStr(crypto.sign(sender, unsigned.bodyBytes())))).explicitGet())
}
}
Expand Down

0 comments on commit ced30ea

Please sign in to comment.