Skip to content

Commit

Permalink
Fixed const
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhmakAS committed Nov 28, 2024
1 parent b4b00ed commit 0f62c2e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 92 deletions.
1 change: 0 additions & 1 deletion casper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type (
Contract = types.Contract
Transaction = types.Transaction
TransactionV1 = types.TransactionV1
TransactionPayload = types.TransactionPayload
TransactionV1Payload = types.TransactionV1Payload
Deploy = types.Deploy
DeployHeader = types.DeployHeader
Expand Down
16 changes: 8 additions & 8 deletions tests/rpc/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func Test_DefaultClient_GetTransaction_Example(t *testing.T) {
require.NoError(t, err)
assert.NotEmpty(t, result.APIVersion)
assert.NotEmpty(t, result.Transaction.Hash)
assert.NotEmpty(t, result.Transaction.Payload)
assert.NotEmpty(t, result.Transaction.Payload.TTL)
assert.NotEmpty(t, result.Transaction.Payload.ChainName)
assert.NotEmpty(t, result.Transaction.Payload.PricingMode)
assert.NotEmpty(t, result.Transaction.Payload.InitiatorAddr)
assert.NotEmpty(t, result.Transaction.Payload.Target)
assert.NotEmpty(t, result.Transaction.Payload.Scheduling)
assert.NotEmpty(t, result.Transaction.Payload.EntryPoint)
assert.NotEmpty(t, result.Transaction)
assert.NotEmpty(t, result.Transaction.TTL)
assert.NotEmpty(t, result.Transaction.ChainName)
assert.NotEmpty(t, result.Transaction.PricingMode)
assert.NotEmpty(t, result.Transaction.InitiatorAddr)
assert.NotEmpty(t, result.Transaction.Target)
assert.NotEmpty(t, result.Transaction.Scheduling)
assert.NotEmpty(t, result.Transaction.EntryPoint)
assert.NotEmpty(t, result.ExecutionInfo.ExecutionResult.Initiator)
assert.NotEmpty(t, result.ExecutionInfo.ExecutionResult.Effects)
assert.NotEmpty(t, result.Transaction.Approvals)
Expand Down
10 changes: 9 additions & 1 deletion tests/sse/events_parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,15 @@ func Test_RawEvent_ParseAsTransactionAcceptedEvent(t *testing.T) {
}

require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.Payload)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.Args)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.ChainName)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.Timestamp)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.TTL)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.InitiatorAddr)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.PricingMode)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.Target)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.EntryPoint)
require.NotEmpty(t, res.TransactionAcceptedPayload.Transaction.Scheduling)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions types/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var ErrArgumentNotFound = errors.New("argument is not found")
type Args []PairArgument

func (args Args) SerializedLength() int {
//TODO implement me
panic("implement me")
bytes, _ := args.Bytes()
return len(bytes)
}

func (args Args) Bytes() ([]byte, error) {
Expand Down
24 changes: 15 additions & 9 deletions types/pricing_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import (
)

const (
PaymentLimitedVariantTag uint8 = 0
PaymentLimitedPaymentAmountIndex uint16 = 1
PaymentLimitedGasPriceToleranceIndex uint16 = 2
PaymentLimitedStandardPaymentIndex uint16 = 3
PaymentLimitedPaymentAmountIndex uint16 = iota + 1
PaymentLimitedGasPriceToleranceIndex
PaymentLimitedStandardPaymentIndex
)

const (
PaymentLimitedVariantTag uint8 = iota
FixedVariantTag
ReservedVariantTag
)

FixedVariantTag uint8 = 1
const (
FixedGasPriceToleranceIndex uint16 = 1
FixedAdditionalComputationFactorIndex uint16 = 2
ReservedVariantTag uint8 = 2
ReservedReceiptIndex uint16 = 1
)

Expand Down Expand Up @@ -237,9 +242,10 @@ func (p *PricingMode) Bytes() ([]byte, error) {
return nil, err
}

//if err = builder.AddField(ReservedReceiptIndex, p.Receipt); err != nil {
// return nil, err
//}
receiptBytes, _ := encoding.NewBytesToBytesEncoder(p.Prepaid.Receipt.Bytes()).Bytes()
if err = builder.AddField(ReservedReceiptIndex, receiptBytes); err != nil {
return nil, err
}
default:
return nil, serialization.ErrFormatting
}
Expand Down
93 changes: 35 additions & 58 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ const (
type Transaction struct {
// Hex-encoded Transaction hash
Hash key.Hash `json:"hash"`
// The Transaction payload
Payload TransactionPayload `json:"payload"`
// List of signers and signatures for this Transaction
Approvals []Approval `json:"approvals"`

// source DeployV1, nil if constructed from TransactionV1
originDeployV1 *Deploy
originTransactionV1 *TransactionV1
}

type TransactionPayload struct {
// Transaction chain name
ChainName string `json:"chain_name"`
// `Timestamp` formatted as per RFC 3339
Expand All @@ -59,29 +48,21 @@ type TransactionPayload struct {
InitiatorAddr InitiatorAddr `json:"initiator_addr"`
// Pricing mode of a Transaction.
PricingMode PricingMode `json:"pricing_mode"`
// ============== Transaction Body =====================
// Args transaction args
Args *Args `json:"args,omitempty"`
// Execution target of a Transaction.
Target TransactionTarget `json:"target"`
// Entry point of a Transaction.
EntryPoint TransactionEntryPoint `json:"entry_point"`
// Scheduling mode of a Transaction.
Scheduling TransactionScheduling `json:"scheduling"`
// List of signers and signatures for this Transaction
Approvals []Approval `json:"approvals"`
// Transaction category
Category uint8 `json:"transaction_category"`
}

type TransactionHeader struct {
// Transaction chain name
ChainName string `json:"chain_name"`
// `Timestamp` formatted as per RFC 3339
Timestamp Timestamp `json:"timestamp"`
// Duration of the `TransactionV1` in milliseconds (from timestamp).
TTL Duration `json:"ttl"`
// The address of the initiator of a Transaction.
InitiatorAddr InitiatorAddr `json:"initiator_addr"`
// Pricing mode of a Transaction.
PricingMode PricingMode `json:"pricing_mode"`
// source DeployV1, nil if constructed from TransactionV1
originDeployV1 *Deploy
originTransactionV1 *TransactionV1
}

func (t *Transaction) GetDeploy() *Deploy {
Expand All @@ -94,18 +75,16 @@ func (t *Transaction) GetTransactionV1() *TransactionV1 {

func NewTransactionFromTransactionV1(v1 TransactionV1) Transaction {
return Transaction{
Hash: v1.Hash,
Payload: TransactionPayload{
ChainName: v1.Payload.ChainName,
Timestamp: v1.Payload.Timestamp,
TTL: v1.Payload.TTL,
InitiatorAddr: v1.Payload.InitiatorAddr,
PricingMode: v1.Payload.PricingMode,
Args: v1.Payload.Fields.NamedArgs.Args,
Target: v1.Payload.Fields.Target,
EntryPoint: v1.Payload.Fields.TransactionEntryPoint,
Scheduling: v1.Payload.Fields.TransactionScheduling,
},
Hash: v1.Hash,
ChainName: v1.Payload.ChainName,
Timestamp: v1.Payload.Timestamp,
TTL: v1.Payload.TTL,
InitiatorAddr: v1.Payload.InitiatorAddr,
PricingMode: v1.Payload.PricingMode,
Args: v1.Payload.Fields.NamedArgs.Args,
Target: v1.Payload.Fields.Target,
EntryPoint: v1.Payload.Fields.TransactionEntryPoint,
Scheduling: v1.Payload.Fields.TransactionScheduling,
Approvals: v1.Approvals,
originTransactionV1: &v1,
}
Expand Down Expand Up @@ -154,29 +133,27 @@ func NewTransactionFromDeploy(deploy Deploy) Transaction {
// Use StandardPayment as true only for payments without explicit `payment amount`
var standardPayment = paymentAmount == 0 && deploy.Payment.ModuleBytes == nil
return Transaction{
Hash: deploy.Hash,
Payload: TransactionPayload{
ChainName: deploy.Header.ChainName,
Timestamp: deploy.Header.Timestamp,
TTL: deploy.Header.TTL,
InitiatorAddr: InitiatorAddr{
PublicKey: &deploy.Header.Account,
},
PricingMode: PricingMode{
Limited: &LimitedMode{
GasPriceTolerance: 1,
PaymentAmount: paymentAmount,
StandardPayment: standardPayment,
},
},
Args: deploy.Session.Args(),
Target: NewTransactionTargetFromSession(deploy.Session),
EntryPoint: transactionEntryPoint,
Scheduling: TransactionScheduling{
Standard: &struct{}{},
Hash: deploy.Hash,
ChainName: deploy.Header.ChainName,
Timestamp: deploy.Header.Timestamp,
TTL: deploy.Header.TTL,
InitiatorAddr: InitiatorAddr{
PublicKey: &deploy.Header.Account,
},
PricingMode: PricingMode{
Limited: &LimitedMode{
GasPriceTolerance: 1,
PaymentAmount: paymentAmount,
StandardPayment: standardPayment,
},
Category: uint8(transactionCategory),
},
Args: deploy.Session.Args(),
Target: NewTransactionTargetFromSession(deploy.Session),
EntryPoint: transactionEntryPoint,
Scheduling: TransactionScheduling{
Standard: &struct{}{},
},
Category: uint8(transactionCategory),
Approvals: deploy.Approvals,
originDeployV1: &deploy,
}
Expand Down
23 changes: 10 additions & 13 deletions types/transaction_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ import (
)

const (
NativeVariant uint8 = 0

StoredVariant uint8 = 1
StoredIdIndex uint16 = 1

StoredRuntimeIndex uint16 = 2
StoredTransferredValueIndex uint16 = 3
SessionIsInstallIndex uint16 = iota + 1
SessionRuntimeIndex
SessionModuleBytesIndex
SessionTransferredValueIndex
SessionSeedIndex
)

SessionVariant uint8 = 2
SessionIsInstallIndex uint16 = 1
SessionRuntimeIndex uint16 = 2
SessionModuleBytesIndex uint16 = 3
SessionTransferredValueIndex uint16 = 4
SessionSeedIndex uint16 = 5
const (
StoredIdIndex uint16 = iota + 1
StoredRuntimeIndex
StoredTransferredValueIndex
)

const (
Expand Down

0 comments on commit 0f62c2e

Please sign in to comment.