Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add size in block_header and fees, size in tx result API #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cmd/derod/rpc/blockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package rpc

//import "fmt"
import "github.com/deroproject/derohe/cryptography/crypto"
import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/blockchain"
import (
"github.com/deroproject/derohe/blockchain"
"github.com/deroproject/derohe/config"
"github.com/deroproject/derohe/cryptography/crypto"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/rpc"
)

// this function is only used by the RPC and is not used by the core and should be moved to RPC interface

Expand Down Expand Up @@ -49,6 +51,7 @@ func GetBlockHeader(chain *blockchain.Blockchain, hash crypto.Hash) (result rpc.
result.SideBlock = chain.Isblock_SideBlock(hash)
result.Reward = blockchain.CalcBlockReward(uint64(result.Height))
result.TXCount = int64(len(bl.Tx_hashes))
result.Size = len(bl.Serialize())

for i := range bl.Tips {
result.Tips = append(result.Tips, bl.Tips[i].String())
Expand Down
38 changes: 25 additions & 13 deletions cmd/derod/rpc/rpc_dero_gettransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@

package rpc

import "fmt"
import "context"
import "encoding/hex"
import "encoding/binary"
import "runtime/debug"
import (
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"runtime/debug"

"github.com/deroproject/derohe/blockchain"
"github.com/deroproject/derohe/config"
"github.com/deroproject/derohe/cryptography/bn256"
"github.com/deroproject/derohe/cryptography/crypto"
"github.com/deroproject/derohe/dvm"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/rpc"
"github.com/deroproject/derohe/transaction"
)

//import "github.com/romana/rlog"
import "github.com/deroproject/derohe/cryptography/crypto"
import "github.com/deroproject/derohe/cryptography/bn256"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/dvm"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/transaction"
import "github.com/deroproject/derohe/blockchain"

func GetTransaction(ctx context.Context, p rpc.GetTransaction_Params) (result rpc.GetTransaction_Result, err error) {

Expand Down Expand Up @@ -58,6 +61,10 @@ func GetTransaction(ctx context.Context, p rpc.GetTransaction_Params) (result rp
related.Block_Height = -1 // not mined
related.In_pool = true

// retrieve fees
related.Fees = tx.Fees()
related.Size = len(tx.Serialize())

result.Txs_as_hex = append(result.Txs_as_hex, hex.EncodeToString(tx.Serialize()))
result.Txs = append(result.Txs, related)
} else {
Expand All @@ -81,6 +88,10 @@ func GetTransaction(ctx context.Context, p rpc.GetTransaction_Params) (result rp

// check whether tx is orphan

// retrieve fees
related.Fees = tx.Fees()
related.Size = len(tx_bytes)

//if chain.Is_TX_Orphan(hash) {
// result.Txs_as_hex = append(result.Txs_as_hex, "") // given empty data
// result.Txs = append(result.Txs, related) // should we have an orphan tx marker
Expand Down Expand Up @@ -164,6 +175,7 @@ func GetTransaction(ctx context.Context, p rpc.GetTransaction_Params) (result rp
}
}
}

for i := range invalid_blid {
related.InvalidBlock = append(related.InvalidBlock, invalid_blid[i].String())
}
Expand Down
4 changes: 3 additions & 1 deletion rpc/daemon_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type BlockHeader_Print struct {
Reward uint64 `json:"reward"`
Tips []string `json:"tips"`
Timestamp uint64 `json:"timestamp"`
Size int `json:"size"` // block header size in bytes
}

type (
Expand Down Expand Up @@ -224,7 +225,8 @@ type (
Code string `json:"code"` // smart contract code at start
BalanceNow uint64 `json:"balancenow"` // if tx is SC, give SC balance at current topo height
CodeNow string `json:"codenow"` // smart contract code at current topo

Fees uint64 `json:"fees"` // fees paid by this tx
Size int `json:"size"` // size of the tx in bytes
}
)

Expand Down