Skip to content

Commit

Permalink
Merge pull request #306 from virtualeconomy/contractFix
Browse files Browse the repository at this point in the history
Update for mainnet release
  • Loading branch information
ncying authored Jan 21, 2022
2 parents dae9b96 + f4476a6 commit 757273c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enablePlugins(sbtdocker.DockerPlugin, JavaServerAppPackaging, JDebPackaging, Sys

name := "vsys"
organization := "systems.v"
version := "0.4.1"
version := "0.4.2"
scalaVersion in ThisBuild := "2.12.6"
crossPaths := false
publishArtifact in (Compile, packageDoc) := false
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/vsys/api/http/contract/ContractApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ case class ContractApiRoute (settings: RestAPISettings,
extends ApiRoute with BroadcastRoute {

override val route = pathPrefix("contract") {
register ~ content ~ info ~ tokenInfo ~ balance ~ execute ~ tokenId ~ vBalance ~ getContractData
register ~ content ~ info ~ tokenInfo ~ balance ~ execute ~ tokenId ~ vBalance ~ getContractData ~ lastToken
}

@Path("/register")
Expand Down Expand Up @@ -115,7 +115,7 @@ case class ContractApiRoute (settings: RestAPISettings,
}
}

@Path("data/{contractId}/{key}")
@Path("/data/{contractId}/{key}")
@ApiOperation(value = "Contract Data", notes = "Get **contract data** by given `contractId` and `key` (default numerical 0).", httpMethod = "Get", authorizations = Array(new Authorization("api_key")))
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response of contract data or error")
Expand All @@ -124,7 +124,7 @@ case class ContractApiRoute (settings: RestAPISettings,
new ApiImplicitParam(name = "contractId", value = "Contract Account", required = true, dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "key", value = "Key", required = true, dataType = "string", paramType = "path")
))
def getContractData: Route = (get & withAuth & path("data" / Segment / Segment)) { (contractId, key) =>
def getContractData: Route = (get & path("data" / Segment / Segment)) { (contractId, key) =>
complete(dataJson(contractId, key))
}

Expand Down Expand Up @@ -225,7 +225,7 @@ case class ContractApiRoute (settings: RestAPISettings,
}
}

@Path("balance/{address}/{tokenId}")
@Path("/balance/{address}/{tokenId}")
@ApiOperation(value = "Token's balance", notes = "Get the **balance** of a specified `tokenId` by a given `address`", httpMethod = "Get")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response of the token balance or error")
Expand Down Expand Up @@ -302,7 +302,7 @@ case class ContractApiRoute (settings: RestAPISettings,
@ApiResponses(Array(new ApiResponse(code = 200, message = "Successful Operation")))
def execute: Route = processRequest("execute", (t: ExecuteContractFunctionRequest) => doBroadcast(TransactionFactory.executeContractFunction(t, wallet, time)))

@Path("contractId/{contractId}/tokenIndex/{tokenIndex}")
@Path("/contractId/{contractId}/tokenIndex/{tokenIndex}")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response of a token id or error")
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object ContractVStableSwap {
val withdrawId: Short = 2
val withdrawPara: Seq[String] = Seq("withdrawer", "amount", "tokenId") ++
Seq("baseTokenId", "targetTokenId", "isValidTokenId",
"isBaseToken", "valueFalse", "baseTokenIfBlock", "isTargetToken", "targetTokenIfBlock")
"isBaseToken", "baseTokenIfBlock", "isTargetToken", "targetTokenIfBlock")
val withdrawDataType: Array[Byte] = Array(DataType.Address.id.toByte, DataType.Amount.id.toByte, DataType.TokenId.id.toByte)
val withdrawTriggerOpcs: Seq[Array[Byte]] = Seq(
assertCaller ++ Array(0.toByte),
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/vsys/blockchain/contract/ContractVSwap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ object ContractVSwap {
assertTrue ++ Array(19.toByte),
cdbvMapValMinus ++ Array(liquidityBalanceMap.index, 2.toByte, 18.toByte),
cdbvMapValAdd ++ Array(liquidityBalanceMap.index, 2.toByte, 17.toByte),
basicMinus ++ Array(18.toByte, 14.toByte, 19.toByte),
cdbvStateValAdd ++ Array(liquidityTokenLeftStateVar.index, 19.toByte),
basicMinus ++ Array(18.toByte, 14.toByte, 20.toByte),
cdbvStateValAdd ++ Array(liquidityTokenLeftStateVar.index, 20.toByte),
cdbvStateValAdd ++ Array(totalSupplyStateVar.index, 14.toByte),
cdbvStateValAdd ++ Array(tokenAReservedStateVar.index, 0.toByte),
cdbvStateValAdd ++ Array(tokenBReservedStateVar.index, 1.toByte),
basicConstantGet ++ DataEntry(Array(1.toByte), DataType.Boolean).bytes ++ Array(20.toByte),
cdbvSet ++ Array(swapStatusStateVar.index, 20.toByte)
basicConstantGet ++ DataEntry(Array(1.toByte), DataType.Boolean).bytes ++ Array(21.toByte),
cdbvSet ++ Array(swapStatusStateVar.index, 21.toByte)
)
lazy val setSwapFunc: Array[Byte] = getFunctionBytes(setSwapId, publicFuncType, nonReturnType, setSwapDataType, setSwapFunctionOpcs)
val setSwapTextualBytes: Array[Byte] = textualFunc("setSwap", Seq(), setSwapPara)
Expand Down Expand Up @@ -427,7 +427,7 @@ object ContractVSwap {
basicMinus ++ Array(13.toByte, 21.toByte, 25.toByte),
basicMultiply ++ Array(25.toByte, 17.toByte, 26.toByte),
basicAdd ++ Array(18.toByte, 16.toByte, 27.toByte)) ++
swapKValueCheck(26.toByte, 27.toByte, 15.toByte, 13.toByte, 14.toByte, 28.toByte) ++ Seq(
swapKValueCheck(26.toByte, 27.toByte, 17.toByte, 13.toByte, 14.toByte, 28.toByte) ++ Seq(
cdbvStateValMinus ++ Array(tokenAReservedStateVar.index, 23.toByte),
cdbvMapValMinus ++ Array(tokenBBalanceMap.index, 3.toByte, 1.toByte),
cdbvStateValAdd ++ Array(tokenBReservedStateVar.index, 1.toByte),
Expand Down Expand Up @@ -498,7 +498,7 @@ object ContractVSwap {
basicMinus ++ Array(14.toByte, 21.toByte, 25.toByte),
basicMultiply ++ Array(25.toByte, 17.toByte, 26.toByte),
basicAdd ++ Array(18.toByte, 16.toByte, 27.toByte)) ++
swapKValueCheck(27.toByte, 26.toByte, 15.toByte, 13.toByte, 14.toByte, 28.toByte) ++ Seq(
swapKValueCheck(27.toByte, 26.toByte, 17.toByte, 13.toByte, 14.toByte, 28.toByte) ++ Seq(
cdbvStateValMinus ++ Array(tokenBReservedStateVar.index, 23.toByte),
cdbvMapValMinus ++ Array(tokenABalanceMap.index, 3.toByte, 1.toByte),
cdbvStateValAdd ++ Array(tokenAReservedStateVar.index, 1.toByte),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ object BasicOpcDiff extends OpcDiffer {
private def formatResB[T] (res: Array[Byte], dt: DataTypeVal[T]): Either[ValidationError, DataEntry] =
DataEntry.create(res, dt).left.map(_ => ValidationError.OverflowError)

def differ(bytes: Array[Byte], data: Seq[DataEntry], t: BasicType.BasicTypeVal) = updateStack(data, bytes.last, t.op(bytes, data))
def differ(bytes: Array[Byte], data: Seq[DataEntry], t: BasicType.BasicTypeVal): Either[ValidationError, Seq[DataEntry]] = updateStack(data, bytes.last, t.op(bytes, data))

override def parseBytesDt(context: ExecutionContext)(bytes: Array[Byte], data: Seq[DataEntry]): Either[ValidationError, Seq[DataEntry]] =
bytes.headOption.flatMap(f => Try(BasicType(f)).toOption) match {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/vsys/network/PeerInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.InetSocketAddress
import io.swagger.annotations._

case class PeerNetworkConnection(@ApiModelProperty(required = true, example = "127.0.0.1")
address: String,
host: String,
@ApiModelProperty(required = true, example = "0")
port: Int)

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/vsys/settings/BlockchainSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object FunctionalitySettings {
//set the value
allowContractTransactionAfterHeight = 6100000,
allowDepositWithdrawContractAfterHeight = 13140520,
allowExchangeContractAfterHeight = Int.MaxValue)
allowExchangeContractAfterHeight = 25416184)

val TESTNET = FunctionalitySettings(
numOfSlots = 60,
Expand Down
8 changes: 5 additions & 3 deletions src/test/scala/tools/ContractTranslator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import vsys.utils.serialization.Deser
import scala.util.{Failure, Success, Try}

object ContractTranslator extends App {
val bytes = ContractVOption.contract.bytes.arr
val bytes = ContractVStableSwap.contract.bytes.arr
val showHex = false

println(Base58.encode(bytes))
Expand Down Expand Up @@ -356,8 +356,8 @@ object ContractTranslator extends App {

case opcType: Byte if opcType == OpcType.TDBAOpc.id =>
y match {
case opcType: Byte if opcType == TDBAType.DepositTDBA.id => "operation.token.deposit(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == TDBAType.WithdrawTDBA.id => "operation.token.withdraw(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == TDBAType.DepositTDBA.id => "operation.token.issue(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == TDBAType.WithdrawTDBA.id => "operation.token.brun(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == TDBAType.TransferTDBA.id => "operation.token.transfer(" + nameList(data(2)) + ", " + nameList(data(3)) + ", " + nameList(data(4)) + ")"
case _ => "--- invalid opc code ---"
}
Expand All @@ -375,6 +375,7 @@ object ContractTranslator extends App {
case opcType: Byte if opcType == CompareType.Ge.id => nameList(data(4)) + " = operation.compare.greaterEqual(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == CompareType.Gt.id => nameList(data(4)) + " = operation.compare.greater(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == CompareType.Beq.id => nameList(data(4)) + " = operation.compare.bytesEqual(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == CompareType.Le.id => nameList(data(4)) + " = operation.compare.lessEqual(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case _ => "--- invalid opc code ---"
}

Expand All @@ -390,6 +391,7 @@ object ContractTranslator extends App {
case opcType: Byte if opcType == BasicType.Convert.id => nameList(data(4)) + " = operation.basic.convert(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case opcType: Byte if opcType == BasicType.ConstantGet.id => nameList(data.last) + " = operation.basic.getConstant(" + strDataEntry(data.slice(2, data.length - 1), nameList) + ")"
case opcType: Byte if opcType == BasicType.SqrtBigInt.id => nameList(data(3)) + " = operation.basic.sqrt(" + nameList(data(2)) + ")"
case opcType: Byte if opcType == BasicType.And.id => nameList(data(4)) + " = operation.basic.and(" + nameList(data(2)) + ", " + nameList(data(3)) + ")"
case _ => "--- invalid opc code ---"
}
case opcType: Byte if opcType == OpcType.IfOpc.id =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class BasicOpcDiffTest extends PropSpec with PropertyChecks with GeneratorDriven
DataEntry(Longs.toByteArray(1), DataType.Amount),
DataEntry(Longs.toByteArray(1), DataType.Amount),
BasicOpcDiff.minus) should be (Right(DataEntry(Longs.toByteArray(0), DataType.Amount)))
BasicOpcDiff.numBiOperation(
DataEntry(Longs.toByteArray(1), DataType.Amount),
DataEntry(Longs.toByteArray(2), DataType.Amount),
BasicOpcDiff.minus) should be (Left(ValidationError.OverflowError))
BasicOpcDiff.numBiOperation(
DataEntry(DataType.arrayShortLengthToByteArray(BigInt(1).toByteArray) ++ BigInt(1).toByteArray, DataType.BigInteger),
DataEntry(DataType.arrayShortLengthToByteArray(BigInt(2).toByteArray) ++ BigInt(2).toByteArray, DataType.BigInteger),
BasicOpcDiff.minus) should be (Right(DataEntry(DataType.arrayShortLengthToByteArray(BigInt(-1).toByteArray) ++ BigInt(-1).toByteArray, DataType.BigInteger)))
BasicOpcDiff.numBiOperation(
DataEntry(Longs.toByteArray(1), DataType.Amount),
DataEntry(Longs.toByteArray(1), DataType.Timestamp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class BlockchainSettingsSpecification extends FlatSpec with Matchers {
settings.functionalitySettings.mintingSpeed should be (1)
settings.functionalitySettings.allowContractTransactionAfterHeight should be (6100000) // same as the setting
settings.functionalitySettings.allowDepositWithdrawContractAfterHeight should be (13140520)
settings.functionalitySettings.allowExchangeContractAfterHeight should be (Int.MaxValue)
settings.functionalitySettings.allowExchangeContractAfterHeight should be (25416184)
settings.genesisSettings.blockTimestamp should be(1543286357457333127L)
settings.genesisSettings.timestamp should be(1543286357457333127L)
settings.genesisSettings.signature should be(ByteStr.decodeBase58("3yYNd7quEWaWytrAug4yGwQvpL3PVJegf9d9NTv9PVE3ouBYJs5PTQqxCjd294uK1zPLj6G5Tk447LqFMWdSFvaQ").toOption)
Expand Down
1 change: 1 addition & 0 deletions vsys-testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vsys {
black-list-residence-time = 30s
peers-broadcast-interval = 5s
connection-timeout = 30s
port = 9923
}
wallet {
password = ""
Expand Down

1 comment on commit 757273c

@fukvsys
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

垃圾,畜生,诈骗狗,你们在开发SK和杨狗妈逼链吗?一地鸡毛!
vsystems is the most shameless and rubbish scam dog in the entire network.
970,000 new vsys scam coins are issued, and only 30 vsys are destroyed every day.
vsys has no applications, no users, and dead chain with no on-chain transactions!

Please sign in to comment.