Skip to content

Instantly share code, notes, and snippets.

Introduction

There’s been a lot of buzz in the recent year around Ethereum cryptocurrency and not without cause. Smart contracts is a new exciting concept that Ethereum introduced. What is it? Ethereum is a distributed ledger (same as bitcoin) but this ledger may contain not only accounts and balances, but also computer programs. Programs are first class citizen on Ethereum blockchain and they are not only stored on it, but they provide functions that might be called (same as you may deposit or withdraw money on the ledger’s account) and store its state on the blockchain. For software developers it would be a good analogy that Ethereum Blockchain is a something similar to a VM. There is a virtual machine with instances of objects that are stored in its memory (smart contract). Instances contain not only code that might be executed but also its state. The main difference is that the everything is stored on distributed ledger instead of RAM. This metaphor is not perfect and simplifie

contract Petunia is owned {
//constructor
function Petunia(address _billingAddress)
function getStatus(uint externalPaymentId) constant returns (string)
function getPrice(uint externalPaymentId) constant returns(uint)
function startNewPayment(uint externalPaymentId, uint price) onlyOwner
if (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else if (typeof Web3 !== 'undefined') {
console.log('No web3? You should consider trying MetaMask!')
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}
myApp.config(function ($provide) {
$provide.provider('ethClinet', function () {
this.$get = function () {
//create instance of it
val generator:StringIdGenerator = PrettyIdGenerator.singleNode
//generate ids
val stringId = generator.nextId()
stringId shouldNot be(empty)
stringId should fullyMatch regex """[A-Z]{4}-[0-9]{5}-[A-Z]{4}-[0-9]{5}"""
//or it might be used just for encoding existing ids
val prettifier = IdPrettifier.default
class IdPrettifier(
encoder: Codec = new AlphabetCodec(Alphabet.Base23),
partsSize: Int = 5,
delimiter: Char = '-',
leadingZeros: Boolean = true
)
prettifiedWithLeading.toIdSeed("AAAA-00000-AAAA-00013") should be(Right(1L))
prettifier.isValid("HPJD-72036-HAPK-58077") should be(true)
trait AcceptanceSpec
extends FlatSpecLike
with TestFutureHelpers
with ScalaFutures
with BeforeAndAfterAll
with OptionValues
with TryValues
with EitherValues
with Eventually
with Matchers
import org.scalatest.{BeforeAndAfterEach, FlatSpecLike, Suite}
trait BaseSpec extends Suite with BeforeAndAfterEach {
override protected def beforeEach(): Unit = {
super.beforeEach()
println("Before Each Base Spec")
}
}
abstract class ExtendedBaseSpec(val name:String) extends BaseSpec {
override protected def beforeEach(): Unit = {
trait AcceptanceSpec
extends FlatSpecLike
with BeforeAndAfterEach
with Matchers
with LazyLogging
with AbstractPatienceConfiguration
abstract class StoreAcceptanceSpec
extends TestKit(ActorSystem("StoreAcceptanceSpec"))
with AcceptanceSpec