Skip to content

Commit

Permalink
feature: Lima HF NameClaimTx update and NameID calculation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Nov 11, 2019
1 parent b51ebb3 commit be88be8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
33 changes: 30 additions & 3 deletions transactions/tx_aens.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ package transactions
import (
"io"
"math/big"
"strings"

"github.com/aeternity/aepp-sdk-go/v6/binary"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/swagguard/node/models"
"github.com/aeternity/aepp-sdk-go/v6/utils"
rlp "github.com/randomshinichi/rlpae"
)

func NameID(name string) (nm string, err error) {
s, err := binary.Blake2bHash([]byte(name))
if err != nil {
return
}
return binary.Encode(binary.PrefixName, s), nil

}

// NamePreclaimTx represents a transaction where one reserves a name on AENS without revealing it yet
type NamePreclaimTx struct {
AccountID string
Expand Down Expand Up @@ -129,6 +140,7 @@ type NameClaimTx struct {
AccountID string
Name string
NameSalt *big.Int
NameFee *big.Int
Fee *big.Int
TTL uint64
AccountNonce uint64
Expand All @@ -145,11 +157,12 @@ func (tx *NameClaimTx) EncodeRLP(w io.Writer) (err error) {
// create the transaction
rlpRawMsg, err := buildRLPMessage(
ObjectTagNameServiceClaimTransaction,
rlpMessageVersion,
2,
aID,
tx.AccountNonce,
tx.Name,
tx.NameSalt,
tx.NameFee,
tx.Fee,
tx.TTL)

Expand All @@ -170,6 +183,7 @@ type nameClaimRLP struct {
AccountNonce uint64
Name string
NameSalt *big.Int
NameFee *big.Int
Fee *big.Int
TTL uint64
}
Expand Down Expand Up @@ -198,6 +212,7 @@ func (tx *NameClaimTx) DecodeRLP(s *rlp.Stream) (err error) {
tx.AccountID = aID
tx.Name = ntx.Name
tx.NameSalt = ntx.NameSalt
tx.NameFee = ntx.NameFee
tx.Fee = ntx.Fee
tx.TTL = ntx.TTL
tx.AccountNonce = ntx.AccountNonce
Expand All @@ -214,6 +229,7 @@ func (tx *NameClaimTx) JSON() (string, error) {
Fee: utils.BigInt(*tx.Fee),
Name: &nameAPIEncoded,
NameSalt: utils.BigInt(*tx.NameSalt),
NameFee: utils.BigInt(*tx.NameFee),
Nonce: tx.AccountNonce,
TTL: tx.TTL,
}
Expand All @@ -238,8 +254,19 @@ func (tx *NameClaimTx) GetGasLimit() *big.Int {
}

// NewNameClaimTx is a constructor for a NameClaimTx struct
func NewNameClaimTx(accountID, name string, nameSalt, fee *big.Int, ttl, accountNonce uint64) *NameClaimTx {
return &NameClaimTx{accountID, name, nameSalt, fee, ttl, accountNonce}
func NewNameClaimTx(accountID, name string, nameSalt, nameFee, fee *big.Int, ttl, accountNonce uint64) *NameClaimTx {
return &NameClaimTx{accountID, name, nameSalt, nameFee, fee, ttl, accountNonce}
}

// CalculateMinNameFee returns the starting bid price for a name on AENS. The
// name argument should include its TLD, e.g. "fdsa.test".
func CalculateMinNameFee(name string) (minNameFee *big.Int) {
n := strings.Split(name, ".") // n = ['fdsa', '.test']
minNameFee = new(big.Int)
l := len(n[0])
nf := config.NameAuctionFee(l)
minNameFee.SetUint64(nf)
return
}

// NamePointer is a go-native representation of swagger generated
Expand Down
36 changes: 34 additions & 2 deletions transactions/tx_aens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ func TestAENSTx(t *testing.T) {
AccountID: "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi",
Name: "fdsa.test",
NameSalt: utils.RequireIntFromString("9795159241593061970"),
NameFee: utils.NewIntFromUint64(0),
Fee: utils.NewIntFromUint64(10),
TTL: uint64(10),
AccountNonce: uint64(1),
},
wantJSON: `{"account_id":"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","fee":10,"name":"nm_9XeniQagC6u2QHpP8f","name_salt":9795159241593061970,"nonce":1,"ttl":10}`,
wantRLP: "tx_+DogAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMBiWZkc2EudGVzdIiH72Vu6YoCUgoKx4dL6Q==",
wantJSON: `{"account_id":"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","fee":10,"name":"nm_9XeniQagC6u2QHpP8f","name_salt":9795159241593061970,"name_fee":0,"nonce":1,"ttl":10}`,
wantRLP: "tx_+DsgAqEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMBiWZkc2EudGVzdIiH72Vu6YoCUgAKCildFnc=",
wantErr: false,
},
{
Expand Down Expand Up @@ -201,3 +202,34 @@ func TestAENSTx(t *testing.T) {
})
}
}

func TestNameID(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
wantNm string
wantErr bool
}{
{
name: "yelimfpisfxrr.chain",
args: args{name: "yelimfpisfxrr.chain"},
wantNm: "nm_o1kMCHjWxBSiUsf8FTQhZso5rr3YorjVEhsgHNb1P3bnPhiYt",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotNm, err := NameID(tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("NameID() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotNm != tt.wantNm {
t.Errorf("NameID() = %v, want %v", gotNm, tt.wantNm)
}
})
}
}

0 comments on commit be88be8

Please sign in to comment.