Skip to content

Commit

Permalink
feat: handle inputs and ouputs (#228)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node and UI APIs have changed.
1. Both Node and UI
* Added:
  - The data structure for input:
  Input {
    OutputIndex   uint16
    TransactionId string
    PublicKey     string
    Signature     string
  }
  - The data structure for output:
  Output {
    Address   string
    HasReward bool
    HasIncome bool
    Value     uint64
  }
* Modified:
  - The transaction data structure for response was:
  TransactionResponse {
    RecipientAddress string
    SenderAddress    string
    SenderPublicKey  string
    Signature        string
    Timestamp        int64
    Value            uint64
    Fee              uint64
  }
  - The transaction data structure for response is:
  TransactionResponse {
    Id        string
    Inputs    []*InputResponse
    Outputs   []*OutputResponse
    Timestamp int64
  }
2. Node
* Added:
  - Endpoint: Get block
  - Endpoint: Get UTXOs
* Removed:
  - Endpoint: Get amount
* Modified:
  - The data structure for target request was:
  TargetRequest {
    Ip   string
    Port uint16
  }
  - The data structure for target request is:
  TargetRequest {
    Ip   string
  }
  - The data structure for transaction request was:
  TransactionRequest {
    Fee                          uint64
    RecipientAddress             string
    SenderAddress                string
    SenderPublicKey              string
    Signature                    string
    Timestamp                    int64
    TransactionBroadcasterTarget string
    Value                        uint64
  }
  - The data structure for transaction request is:
  TransactionRequest {
    Inputs                       []InputRequest
    Outputs                      []OutputRequest
    Timestamp                    int64
    TransactionBroadcasterTarget string
  }
3. UI
* Added:
  - Endpoint: GET transaction/info
* Modified:
  - The data structure for transaction request was:
  TransactionRequest {
    Fee                          uint64
    RecipientAddress             string
    SenderAddress                string
    SenderPublicKey              string
    Signature                    string
    Timestamp                    int64
    Value                        uint64
  }
  - The data structure for transaction request is:
  TransactionRequest {
    Inputs    []InputRequest
    Outputs   []OutputRequest
    Timestamp int64
  }
  • Loading branch information
JeremyPansier committed Sep 15, 2023
1 parent 44fc98a commit 5ca3390
Show file tree
Hide file tree
Showing 57 changed files with 2,889 additions and 1,193 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
[![Doc](https://img.shields.io/badge/doc-wiki-blue?logo=github)](https://github.com/my-cloud/ruthenium/wiki)
[![Doc](https://img.shields.io/badge/doc-whitepaper-blue?logo=github)](https://github.com/my-cloud/ruthenium/wiki/Whitepaper)

Golang implementation of the Ruthenium blockchain protocol.
Golang implementation of the Ruthenium protocol.

You will find a detailed description of the project in the [wiki](https://github.com/my-cloud/ruthenium/wiki/Home). To understand the motivations behind the creation of this blockchain, you can peruse the comprehensive details outlined in the Ruthenium [whitepaper](https://github.com/my-cloud/ruthenium/wiki/Whitepaper).

## Quickstart
There are two ways to use the Ruthenium blockchain. You can either use your own build from [sources](https://github.com/my-cloud/ruthenium/releases) (Option A) or use a docker image provided in the [repository packages](https://github.com/my-cloud/ruthenium/pkgs/container/ruthenium) (Option B).
There are two ways to run a Ruthenium node. You can either use your own build from [sources](https://github.com/my-cloud/ruthenium/releases) (Option A) or use a docker image provided in the [repository packages](https://github.com/my-cloud/ruthenium/pkgs/container/ruthenium) (Option B).

### Prerequisites
* Option A (using sources):
Expand Down Expand Up @@ -91,7 +91,7 @@ For a [tutorial to create a first blockchain in Go][1], thanks to [Yuko Sakai][2
![license.png](doc/license.png)

## Project status
[![Commit activity](https://img.shields.io/github/commit-activity/m/my-cloud/ruthenium?logo=github)](https://github.com/my-cloud/ruthenium/commits/main)
[![Commit activity](https://img.shields.io/github/commit-activity/y/my-cloud/ruthenium?logo=github)](https://github.com/my-cloud/ruthenium/commits/main)

[![Maintainability](https://sonarcloud.io/api/project_badges/measure?project=my-cloud_ruthenium&metric=sqale_rating)](https://sonarcloud.io/component_measures?id=my-cloud_ruthenium&metric=sqale_rating)
[![Security](https://sonarcloud.io/api/project_badges/measure?project=my-cloud_ruthenium&metric=security_rating)](https://sonarcloud.io/component_measures?id=my-cloud_ruthenium&metric=security_rating)
Expand Down
3 changes: 2 additions & 1 deletion config/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"genesisAmountInParticles": 10000000000000,
"halfLifeInDays": 373.59,
"maxOutboundsCount": 8,
"minimalTransactionFee": 1000,
"particlesPerToken": 100000000,
"synchronizationIntervalInSeconds": 10,
"validationIntervalInSeconds": 60,
"verificationsCountPerValidation": 6
}
}
14 changes: 4 additions & 10 deletions src/encryption/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Signature struct {
s *big.Int
}

func NewSignature(marshaledTransaction []byte, privateKey *PrivateKey) (*Signature, error) {
hash := sha256.Sum256(marshaledTransaction)
func NewSignature(bytes []byte, privateKey *PrivateKey) (*Signature, error) {
hash := sha256.Sum256(bytes)
r, s, err := ecdsa.Sign(rand.Reader, privateKey.PrivateKey, hash[:])
if err != nil {
return nil, fmt.Errorf("failed to sign transaction: %w", err)
Expand All @@ -41,15 +41,9 @@ func (signature *Signature) String() string {
return fmt.Sprintf("%064x%064x", signature.r, signature.s)
}

func (signature *Signature) Verify(marshaledTransaction []byte, publicKey *PublicKey, transactionSenderAddress string) bool {
func (signature *Signature) Verify(marshaledTransaction []byte, publicKey *PublicKey) bool {
hash := sha256.Sum256(marshaledTransaction)
isSignatureValid := ecdsa.Verify(publicKey.PublicKey, hash[:], signature.r, signature.s)
var isTransactionValid bool
if isSignatureValid {
publicKeyAddress := publicKey.Address()
isTransactionValid = transactionSenderAddress == publicKeyAddress
}
return isTransactionValid
return ecdsa.Verify(publicKey.PublicKey, hash[:], signature.r, signature.s)
}

func string2BigIntTuple(s string) (big.Int, big.Int, error) {
Expand Down
33 changes: 0 additions & 33 deletions src/encryption/wallet.go

This file was deleted.

0 comments on commit 5ca3390

Please sign in to comment.