Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
duelingbenjos committed Jun 14, 2024
1 parent cfeb2f0 commit 3ff105f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
14 changes: 13 additions & 1 deletion src/smart-contracts/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ description: Functions in Contracting.

# Functions

**Types of functions in Contracting**
## Types of functions in Contracting

:::info Functions in Contracting are defined by the use of decorators
Decorators are special keywords situated above a function definition that tell the system how to handle the function.

The decorators used in Contracting are:

- `@export`
- A public function that can be called by any contract or person
- `@construct`
- A function that is executed when the contract is submitted
- No decorator
- A private function that can only be called by the smart contract itself
:::
## @export
You have to define at least one `@export` decorated function in your smart contract. Otherwise, the smart contract has no functions for people to call.

Expand Down
5 changes: 5 additions & 0 deletions src/smart-contracts/modules/crypto-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ def verify_signature(vk: str, msg: str, signature: str):
# Return the result of the verification
return is_valid
```

:::tip Additional methods for signing & verifying messages off-chain can be found in :
- [xian-js](/tools/xian-js#sign-a-message)
- [xian-py](/tools/xian-py#sign-message-with-private-key)
:::
20 changes: 10 additions & 10 deletions src/tools/xian-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ xian-js is a JavaScript / Typescript library for interacting with the Xian netwo

### Wallet Functions

#### Create a Xian Keypair
## Create a Xian Keypair

```typescript
import Xian from "xian-js"
Expand All @@ -30,7 +30,7 @@ console.log(new_wallet)
```


### Create a new BIP39 / BIP 32 compatible wallet
## Create a new BIP39 / BIP 32 compatible wallet
- **BIP39** = 24 word mnemonic
- **BIP32** = derivation path

Expand All @@ -48,7 +48,7 @@ console.log(new_wallet_bip39)

```

### Create a wallet from sk (private key)
## Create a wallet from sk (private key)

```javascript
const sk = 'a6b72cb3d1160c26f9f39a8f1d4a3c7c0da2ac59d193b66ac5f919ec77f28915'
Expand All @@ -66,7 +66,7 @@ console.log(wallet)
}

```
### Restore a BIP39 / BIP 32 compatible wallet
## Restore a BIP39 / BIP 32 compatible wallet
- **BIP39** = 24 word mnemonic
- **BIP32** = derivation path

Expand All @@ -86,7 +86,7 @@ console.log(wallet)
```


### Get a public key (vk) from a private key (sk)
## Get a public key (vk) from a private key (sk)
Takes the sk as an argument and returns the vk
```javascript
let sk = "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"
Expand All @@ -96,7 +96,7 @@ console.log(vk)
>> 'ea2cee33f9478d767d67afe345592ef36446ee04f8d588fa76942e6569a53298'
```

### Sign a message
## Sign a message
Signs a string payload
```javascript
const stringBuffer = Buffer.from('message')
Expand All @@ -109,7 +109,7 @@ console.log(signedMessage)
>> '982c204fe88e620f3319558aa6b11f9d8be75b99b3199f434f5edf2834a9c52059ba4ea3d623ac1d550170e532e919c364aad1333f757f8f22e0355cb1dd8c09'
```

#### Verify signature
## Verify signature
verify a payload
```javascript
let validSignature = wallet.verify(vk, messageBytes, signedMessage)
Expand All @@ -123,7 +123,7 @@ Public Testnet masternode host is `https://testnet.xian.org`

Use `Xian.TransactionBuilder(network_info, tx_info)` to create a new Xian transaction.

### Create network_info object
## Create network_info object
create an object that describes the masternode/network that you are going to send the transcation to.
```typescript

Expand Down Expand Up @@ -155,12 +155,12 @@ let txInfo: I_TxInfo = {
}
```

### Create transaction
## Create transaction
```javascript
let tx = new Xian.TransactionBuilder(networkInfo, txInfo)
```

### Send transaction
## Send transaction
```typescript
let senderSk = "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"

Expand Down
26 changes: 13 additions & 13 deletions src/tools/xian-py.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pip install xian-py

# Wallet

### Create new wallet
## Create new wallet
```python
from xian_py.wallet import Wallet

# Create wallet from scratch
wallet = Wallet()
```

### Create wallet from existing private key
## Create wallet from existing private key
```python
from xian_py.wallet import Wallet

Expand All @@ -33,7 +33,7 @@ privkey = 'ed30796abc4ab47a97bfb37359f50a9c362c7b304a4b4ad1b3f5369ecb6f7fd8'
wallet = Wallet(privkey)
```

### Get private key and public key
## Get private key and public key
```python
from xian_py.wallet import Wallet

Expand All @@ -48,7 +48,7 @@ privkey = wallet.private_key
print(f'private key: {privkey}')
```

### Sign message with private key
## Sign message with private key
```python
from xian_py.wallet import Wallet

Expand All @@ -62,7 +62,7 @@ print(f'Signed message: {signed}')

# Xian

### Send XIAN tokens
## Send XIAN tokens
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand All @@ -79,7 +79,7 @@ print(f'success: {send_xian["success"]}')
print(f'tx_hash: {send_xian["tx_hash"]}')
```

### Submit contract
## Submit contract
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand All @@ -106,7 +106,7 @@ print(f'success: {submit["success"]}')
print(f'tx_hash: {submit["tx_hash"]}')
```

### Submit contract with constructor arguments
## Submit contract with constructor arguments
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand Down Expand Up @@ -139,7 +139,7 @@ print(f'success: {submit["success"]}')
print(f'tx_hash: {submit["tx_hash"]}')
```

### Approve contract and retrieve approved amount
## Approve contract and retrieve approved amount
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand All @@ -162,7 +162,7 @@ print(f'approved success: {approved["success"]}')
print(f'approved tx_hash: {approved["tx_hash"]}')
```

### Get XIAN token balance of an address
## Get XIAN token balance of an address
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand All @@ -174,7 +174,7 @@ balance = xian.get_balance('b6504cf056e264a4c1932d5de6893d110db5459ab4f742eb415d
print(f'balance: {balance}')
```

### Get custom token balance for a contract
## Get custom token balance for a contract

Contracts can have token balances and in this example `con_token` is a token contract and we want to check the balance of that token in the contract `con_test_contract`

Expand All @@ -189,7 +189,7 @@ balance = xian.get_balance('con_test_contract', contract='con_token')
print(f'balance: {balance}')
```

### Retrieve transaction by hash
## Retrieve transaction by hash
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand All @@ -202,7 +202,7 @@ tx = xian.get_tx('2C403B728E4AFFD656CAFAD38DD3E34C7CC8DA06464A7A5B1E8A426290F505
print(f'transaction: {tx}')
```

### Retrieve data from a contract
## Retrieve data from a contract

In this case we assume that there is a contract `con_testing` that has a variable called `test`

Expand All @@ -216,7 +216,7 @@ print(f'data: {tx}')

# Transactions

### Send a transaction - High level usage
## Send a transaction - High level usage
```python
from xian_py.wallet import Wallet
from xian_py.xian import Xian
Expand Down

0 comments on commit 3ff105f

Please sign in to comment.