Skip to content

Commit

Permalink
Merge pull request #11 from CrisBRM/patch-3
Browse files Browse the repository at this point in the history
English fixes
  • Loading branch information
smalloranges committed Oct 11, 2018
2 parents 234d63e + 6eafb61 commit d99e77b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
30 changes: 15 additions & 15 deletions docs/dapp-development/smart_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Languages

In Nebulas, there are two supported smart contract languages:
In Nebulas, there are two supported languages for writing smart contracts:

* [JavaScript](https://en.wikipedia.org/wiki/JavaScript)
* [TypeScript](https://en.wikipedia.org/wiki/TypeScript)
Expand All @@ -11,12 +11,12 @@ They are supported by the integration of [Chrome V8](https://developers.google.c

## Execution Model

The diagram below is the Execution Model of Smart Contract:
The diagram below is the Execution Model of the Smart Contract:

![Smart Contract Execution Model](../resources/smart_contract_execution_model.png)

1. All src of Smart Contract and arguments are packaged in Transaction and deployed on Nebulas.
2. The execution of Smart Contract are divided into two phases:
1. The whole src of the Smart Contract and its arguments are packaged in the Transaction and deployed on Nebulas.
2. The execution of Smart Contract is divided in two phases:
1. Preprocess: inject tracing instruction, etc.
2. Execute: generate executable src and execute it.

Expand All @@ -28,9 +28,9 @@ Contracts in Nebulas are similar to classes in object-oriented languages. They c

A contract must be a Prototype Object or Class in JavaScript or TypeScript.

A Contract must include an `init` function, it will be executed only once when deploying. Functions, named starting with `_` are `private`, can't be executed in Transaction. The others are all `public` and can be executed in Transaction.
A Contract must include an `init` function, it will be executed only once when deploying. Functions whose names start with `_` are `private` and can't be executed in a Transaction. The others are all `public` and can be executed in a Transaction.

Since Contract is executed in Chrome V8, all instance variables are in memory, it's not wise to save all of them to [state trie](https://github.com/nebulasio/wiki/blob/master/merkle_trie.md) in Nebulas. In Nebulas, we provide `LocalContractStorage` and `GlobalContractStorage` objects to help developers define fields needing to be saved to state trie. And those fields should be defined in `constructor` of Contract, before other functions.
Since the Contract is executed on Chrome V8, all instance variables are in memory, it's not wise to save all of them to [state trie](https://github.com/nebulasio/wiki/blob/master/merkle_trie.md) in Nebulas. In Nebulas, we provide `LocalContractStorage` and `GlobalContractStorage` objects to help developers define fields needing to be saved to state trie. And those fields should be defined in `constructor` of the Contract, before other functions.

The following is a sample contract:

Expand Down Expand Up @@ -71,7 +71,7 @@ In JavaScript, there is no function visibility, all functions defined in prototy

In Nebulas, we define two kinds of visibility `public` and `private`:

* `public` All functions whose name matches regexp `^[a-zA-Z$][A-Za-z0-9_$]*$` are public, except `init`. Public functions can be called via Transaction.
* `public` All functions whose name matches the regexp `^[a-zA-Z$][A-Za-z0-9_$]*$` are public, except `init`. Public functions can be called via Transaction.
* `private` All functions whose name starts with `_` are private. A private function can only be called by public functions.

## Global Objects
Expand Down Expand Up @@ -114,7 +114,7 @@ The global console can be used without calling `require('console')`.

### LocalContractStorage

The `LocalContractStorage` module provides a state trie based storage capability. It accepts string only key value pairs. And all data are stored to a private state trie associated with current contract address, only the contract can access them.
The `LocalContractStorage` module provides a state trie based storage capability. It accepts string only key value pairs. And all data is stored to a private state trie associated with the current contract address. Only the contract can access it.

```typescript
interface Descriptor {
Expand Down Expand Up @@ -187,7 +187,7 @@ interface StorageMap {

### BigNumber

The `BigNumber` module use the [bignumber.js](https://github.com/MikeMcl/bignumber.js), a JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. The contract can use `BigNumber` directly to handle the value of the transaction and other values transfer.
The `BigNumber` module uses the [bignumber.js](https://github.com/MikeMcl/bignumber.js), a JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. The contract can use `BigNumber` directly to handle the value of the transaction and other value transfer.

```javascript
var value = new BigNumber(0);
Expand All @@ -197,7 +197,7 @@ value.plus(1);

### Blockchain

The `Blockchain` module provides a object for contracts to obtain transactions and blocks executed by the current contract. Also, the NAS can be transferred from the contract and the address check is provided.
The `Blockchain` module provides an object for contracts to obtain transactions and blocks executed by the current contract. Also, the NAS can be transferred from the contract and the address check is provided.

Blockchain API:

Expand Down Expand Up @@ -295,7 +295,7 @@ module.exports = SampleContract;

### Event

The `Event` module records execution events in contract. The recorded events are stored in the event trie on the chain, which can be fetched by `FetchEvents` method in block with the execution transaction hash. All contract event topics have a `chain.contract.` prefix before the topic they set in contract.
The `Event` module records execution events in the contract. The recorded events are stored in the event trie on the chain, which can be fetched by `FetchEvents` method in block with the execution transaction hash. All contract event topics have a `chain.contract.` prefix before the topic they set in contract.

```javascript
Event.Trigger(topic, obj);
Expand All @@ -304,11 +304,11 @@ Event.Trigger(topic, obj);
* `topic`: user-defined topic
* `obj`: JSON object

You can see the example in `SampleContract` before.
You can see the example in `SampleContract` above.

### Math.random

* `Math.random()` returns a floating-point, pseudo-random number in the range from 0 inclusive up to but not including 1. The typical usage is:
* `Math.random()` returns a floating-point, pseudo-random number in the range from 0 inclusive, up to, but not including 1. The typical usage is:

```javascript
"use strict";
Expand Down Expand Up @@ -336,7 +336,7 @@ BankVaultContract.prototype = {
module.exports = BankVaultContract;
```

* `Math.random.seed(myseed)` if needed, you can use this method to reset random seed. The argument `myseed` must be a **string**.
* `Math.random.seed(myseed)` if needed, you can use this method to reset the random seed. The argument `myseed` must be a **string**.

\`\`\`js

Expand Down Expand Up @@ -402,7 +402,7 @@ Tips:

### accept

this method is aimed to make it possible to send a binary transfer to a contract account. As the `to` is a smart contact address, which has declared a function `accept()` and it excutes correctly, the transfer will succeed. If the Tx is a non-binary Tx,it will be treated as a normal function.
this method aims to make it possible to send a binary transfer to a contract account. As `to` is a smart contact address, which has declared the function `accept()` and it excuted correctly, the transfer will succeed. If the Tx is a non-binary Tx, it will be treated as a normal function.

```javascript
"use strict";
Expand Down
22 changes: 11 additions & 11 deletions docs/dapp-development/testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

## Introduction

We are glad to release Nebulas Testnet here. It simulate the Nebulas network and NVM, and allow developers to interact with Nebulas without paying the cost of gas.
We are glad to release the Nebulas Testnet. It simulates the Nebulas network and NVM, and allows developers to interact with Nebulas without paying the cost of gas.

```text
https://github.com/nebulasio/go-nebulas/tree/testnet
```

### Configuration

The testnet configuration files are in folder [`testnet/conf`](https://github.com/nebulasio/go-nebulas/tree/testnet/testnet/conf) under `testnet` branch, including
The testnet configuration files are in the folder [`testnet/conf`](https://github.com/nebulasio/go-nebulas/tree/testnet/testnet/conf) under `testnet` branch, including

#### genesis.conf

All configurable information about genesis block is defined in genesis.conf, including
All configurable information about the genesis block is defined in genesis.conf, including

* **meta.chain\_id:** chain identity
* **consensus.dpos.dynasty:** the initial dynasty of validators
Expand Down Expand Up @@ -44,16 +44,16 @@ Test Endpoint:

* [GetNebState](https://github.com/nebulasio/wiki/blob/master/rpc.md#getnebstate) : returns nebulas client info.
* [GetAccountState](https://github.com/nebulasio/wiki/blob/master/rpc.md#getaccountstate): returns the account balance and nonce.
* [LatestIrreversibleBlock](https://github.com/nebulasio/wiki/blob/master/rpc.md#latestirreversibleblock): returns the lastest irreversible block.
* [Call](https://github.com/nebulasio/wiki/blob/master/rpc.md#call): execute smart contract locally. the tx won't be submitted on chain.
* [SendRawTransaction](https://github.com/nebulasio/wiki/blob/master/rpc.md#sendrawtransaction): submit signed transaction. The transaction must be signed before send.
* [GetTransactionReceipt](https://github.com/nebulasio/wiki/blob/master/rpc.md#gettransactionreceipt): get transaction receipt info by tansaction hash.
* [LatestIrreversibleBlock](https://github.com/nebulasio/wiki/blob/master/rpc.md#latestirreversibleblock): returns the latest irreversible block.
* [Call](https://github.com/nebulasio/wiki/blob/master/rpc.md#call): execute smart contract locally. The tx won't be submitted on chain.
* [SendRawTransaction](https://github.com/nebulasio/wiki/blob/master/rpc.md#sendrawtransaction): submit signed transaction. The transaction must be signed before sending.
* [GetTransactionReceipt](https://github.com/nebulasio/wiki/blob/master/rpc.md#gettransactionreceipt): get transaction receipt info from the transaction hash.

More Nebulas APIs at [RPC](https://github.com/nebulasio/wiki/blob/master/rpc.md).

#### Token Claim
#### Claim Tokens

Every email can claim some tokens every day at [here](https://testnet.nebulas.io/claim).
Each email can claim tokens every day [here](https://testnet.nebulas.io/claim).

## Tutorials

Expand All @@ -73,7 +73,7 @@ Every email can claim some tokens every day at [here](https://testnet.nebulas.io
4. [智能合约存储区介绍](https://github.com/nebulasio/wiki/blob/master/tutorials/[中文]%20Nebulas%20101%20-%2004%20智能合约存储区.md)
5. [通过RPC接口与星云链交互](https://github.com/nebulasio/wiki/blob/master/tutorials/[中文]%20Nebulas%20101%20-%2005%20通过RPC接口与星云链交互.md)

## Contribution
## Contributing

Feel free to join Nebulas Testnet. If you did find something wrong, please [submit a issue](https://github.com/nebulasio/go-nebulas/issues/new) or [submit a pull request](https://github.com/nebulasio/go-nebulas/pulls) to let us know, we will add your name and url to this page soon.
Feel free to join Nebulas Testnet. If you did find something wrong, please [submit an issue](https://github.com/nebulasio/go-nebulas/issues/new) or [submit a pull request](https://github.com/nebulasio/go-nebulas/pulls) to let us know, we will add your name and url to this page as soon as possible.

0 comments on commit d99e77b

Please sign in to comment.