An open API service indexing awesome lists of open source software.

https://github.com/soliscript/soliscript

soliscript - run blockchain contracts in rubidity (with 100%-solidity compatible data types & abis) on an ethereum simulacrum in your own home for fun & profit (for free)
https://github.com/soliscript/soliscript

abi blockchain ethereum rubidity simulacrum solidity soliscript uint256

Last synced: 2 months ago
JSON representation

soliscript - run blockchain contracts in rubidity (with 100%-solidity compatible data types & abis) on an ethereum simulacrum in your own home for fun & profit (for free)

Awesome Lists containing this project

README

          

# Soliscript

soliscript - run blockchain contracts in rubidity (with 100%-solidity compatible data types & abis) on an ethereum simulacrum in your own home for fun & profit (for free)

* home :: [github.com/soliscript/soliscript](https://github.com/soliscript/soliscript)
* bugs :: [github.com/soliscript/soliscript/issues](https://github.com/soliscript/soliscript/issues)
* gem :: [rubygems.org/gems/soliscript](https://rubygems.org/gems/soliscript)
* rdoc :: [rubydoc.info/gems/soliscript](http://rubydoc.info/gems/soliscript)

## What's Solidity?! What's Rubidity?!

See [**Solidity - Contract Application Binary Interface (ABI) Specification** »](https://docs.soliditylang.org/en/latest/abi-spec.html)

See [**Rubidity - Ruby for Layer 1 (L1) Contracts / Protocols with "Off-Chain" Indexer** »](https://github.com/s6ruby/rubidity)

## Usage

Let's try the contract samples from
the free (online) booklet titled ["Programming Crypto Blockchain Contracts Step-by-Step Book / Guide"](https://github.com/s6ruby/programming-crypto-contracts)
in Soliscript (Rubidity with Ethereum Simulacrum)!

### Simple Ponzi - Investment of a Lifetime!

Let's start with a simple ponzi scheme contract:

``` ruby
class SimplePonzi < Contract

storage current_investor: Address,
current_investment: UInt

sig []
def constructor
@current_investor = msg.sender
end

sig []
def receive # @payable default function
minimum_investment = @current_investment * 11/10
assert msg.value >= minimum_investment,
'new investments must be 10% greater than current'

# record new investor
previous_investor = @current_investor
@current_investor = msg.sender
@current_investment = msg.value

# pay out previous investor
previous_investor.send( msg.value )
end

end # class SimplPonzi
```

(Source: [`ponzi_simple.rb`](sandbox/ponzi_simple.rb))

Let's look at the first simple ponzi contract script. The idea is:

The money sent in by the latest investor
gets paid out to the previous investor and because every
new investment must be at least 10% larger than the last
investment - EVERY INVESTOR WINS! (*)

(*): Except the last "sucker" is HODLing the bag waiting for a greater fool.

Let's setup some test accounts with funny money:

``` ruby
genesis = '0x'+'11'*20 #=> '0x1111111111111111111111111111111111111111'
alice = '0x'+'aa'*20 #=> '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
bob = '0x'+'bb'*20 #=> '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
charlie = '0x'+'cc'*20 #=> '0xcccccccccccccccccccccccccccccccccccccccc'

## setup test accounts with starter balance
Account[ genesis ].balance = 0
Account[ alice ].balance = 1_000_000
Account[ bob ].balance = 1_000_000
Account[ charlie ].balance = 1_000_000

## (pp) pretty print all known accounts with balance
pp Account.all
```

(Source: [`run_ponzi_simple.rb`](sandbox/run_ponzi_simple.rb))

printing:

```
[# #

Simulacrum.send_transaction( from: alice, to: ponzi, value: 100_000 )
#=> #

Simulacrum.send_transaction( from: bob, to: ponzi, value: 111_000 )
#=> #

Simulacrum.send_transaction( from: charlie, to: ponzi, value: 200_000 )
#=> #

## (pp) pretty print all known accounts with balance
pp Account.all
```

Resulting in:

```
[#