Skip to content

Commit

Permalink
update transaction deposit attributes name
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 13, 2023
1 parent 401669c commit c58c734
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
10 changes: 5 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ func signTransactionCmd(c *cli.Context) error {
for _, in := range raw.Inputs {
if d := in.Deposit; d != nil {
tx.AddDepositInput(&common.DepositData{
Chain: d.Chain,
AssetKey: d.AssetKey,
TransactionHash: d.TransactionHash,
OutputIndex: d.OutputIndex,
Amount: d.Amount,
Chain: d.Chain,
AssetKey: d.AssetKey,
Transaction: d.TransactionHash,
Index: d.OutputIndex,
Amount: d.Amount,
})
} else {
tx.AddInput(in.Hash, in.Index)
Expand Down
4 changes: 2 additions & 2 deletions common/decoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ func (dec *Decoder) ReadInput() (*Input, error) {
if err != nil {
return nil, err
}
d.TransactionHash = string(th)
d.Transaction = string(th)

oi, err := dec.ReadUint64()
if err != nil {
return nil, err
}
d.OutputIndex = oi
d.Index = oi

amt, err := dec.ReadInteger()
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions common/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type DepositData struct {
Chain crypto.Hash
AssetKey string
TransactionHash string
OutputIndex uint64
Amount Integer
Chain crypto.Hash
AssetKey string
Transaction string
Index uint64
Amount Integer
}

func (d *DepositData) Asset() *Asset {
Expand All @@ -24,7 +24,7 @@ func (d *DepositData) Asset() *Asset {
}

func (d *DepositData) UniqueKey() crypto.Hash {
index := fmt.Sprintf("%s:%d", d.TransactionHash, d.OutputIndex)
index := fmt.Sprintf("%s:%d", d.Transaction, d.Index)
return crypto.Sha256Hash([]byte(index)).ForNetwork(d.Chain)
}

Expand All @@ -50,9 +50,9 @@ func (tx *Transaction) verifyDepositFormat() error {
chainId := deposit.Asset().ChainId
switch chainId {
case ethereum.EthereumChainId:
return ethereum.VerifyTransactionHash(deposit.TransactionHash)
return ethereum.VerifyTransactionHash(deposit.Transaction)
case bitcoin.BitcoinChainId:
return bitcoin.VerifyTransactionHash(deposit.TransactionHash)
return bitcoin.VerifyTransactionHash(deposit.Transaction)
}
return fmt.Errorf("invalid deposit chain id %s", chainId)
}
Expand Down
80 changes: 40 additions & 40 deletions common/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ func TestDeposit(t *testing.T) {
require.True(strings.Contains(err.Error(), "invalid inputs"))

tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 1,
Amount: NewIntegerFromString("1007"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 1,
Amount: NewIntegerFromString("1007"),
})
ver = tx.AsVersioned()
signed = &ver.SignedTransaction
Expand All @@ -74,11 +74,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
ver = tx.AsVersioned()
signed = &ver.SignedTransaction
Expand All @@ -88,11 +88,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
si := crypto.Blake3Hash([]byte(transactionHash + "1"))
seed = append(si[:], si[:]...)
Expand All @@ -108,11 +108,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
si = crypto.Blake3Hash([]byte(transactionHash))
seed = append(si[:], si[:]...)
Expand All @@ -128,11 +128,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
si = crypto.Blake3Hash([]byte(transactionHash))
seed = append(si[:], si[:]...)
Expand All @@ -147,11 +147,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
si = crypto.Blake3Hash([]byte(transactionHash))
seed = append(si[:], si[:]...)
Expand All @@ -166,11 +166,11 @@ func TestDeposit(t *testing.T) {

tx = NewTransactionV5(assetID)
tx.AddDepositInput(&DepositData{
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
TransactionHash: transactionHash,
OutputIndex: 0,
Amount: NewIntegerFromString("1006"),
Chain: ethereum.EthereumChainId,
AssetKey: assetKey,
Transaction: transactionHash,
Index: 0,
Amount: NewIntegerFromString("1006"),
})
si = crypto.Blake3Hash([]byte(transactionHash))
seed = append(si[:], si[:]...)
Expand Down
6 changes: 3 additions & 3 deletions common/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ func (enc *Encoder) EncodeInput(in *Input) {
enc.WriteInt(len(d.AssetKey))
enc.Write([]byte(d.AssetKey))

enc.WriteInt(len(d.TransactionHash))
enc.Write([]byte(d.TransactionHash))
enc.WriteInt(len(d.Transaction))
enc.Write([]byte(d.Transaction))

enc.WriteUint64(d.OutputIndex)
enc.WriteUint64(d.Index)
enc.WriteInteger(d.Amount)
}

Expand Down
10 changes: 5 additions & 5 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ func transactionToMap(tx *common.VersionedTransaction) map[string]any {
} else if d := in.Deposit; d != nil {
inputs = append(inputs, map[string]any{
"deposit": map[string]any{
"chain": d.Chain,
"asset_key": d.AssetKey,
"transaction_hash": d.TransactionHash,
"output_index": d.OutputIndex,
"amount": d.Amount,
"chain": d.Chain,
"asset": d.AssetKey,
"transaction": d.Transaction,
"index": d.Index,
"amount": d.Amount,
},
})
} else if m := in.Mint; m != nil {
Expand Down

0 comments on commit c58c734

Please sign in to comment.