Skip to content

Commit

Permalink
Merge pull request #24 from Salvionied/ExtensibleMetadata
Browse files Browse the repository at this point in the history
Extensible metadata
  • Loading branch information
Salvionied authored Apr 24, 2024
2 parents 39d390b + d5679fa commit df0e5f2
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 41 deletions.
8 changes: 4 additions & 4 deletions ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1533,10 +1533,10 @@ func (b *Apollo) Submit() (serialization.TransactionId, error) {
*/
func (b *Apollo) LoadTxCbor(txCbor string) (*Apollo, error) {
tx := Transaction.Transaction{}
cborBytes, err := hex.DecodeString(txCbor)
if err != nil {
return nil, err
}
cborBytes, err := hex.DecodeString(txCbor)
if err != nil {
return nil, err
}
err = cbor.Unmarshal(cborBytes, &tx)
if err != nil {
return b, err
Expand Down
19 changes: 19 additions & 0 deletions ApolloBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,3 +1138,22 @@ func TestCongestedBuild(t *testing.T) {
t.Error("Tx is not correct")
}
}

func TestMapPDDecodeEncode(t *testing.T) {
val := "84ac00828258205af098c47e6539e03dce07fb9cd83ba630bd901e6943db894c70f656a480fa5a01825820ca0ebc40b02aeeaa0c8a84be94c9146bad85f249d6b98f840fd70f894a1de370020185a30058391155ff0e63efa0694e8065122c552e80c7b51768b7f20917af25752a7c3b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e401821a006acfc0a1581c3c468b2a275a7df4b33625335232d4cfb45e651d289b2e0737856184a147457a43464f4e4101028201d81858b9d8799fa200a140a1401a001e848001a09fd8799f4040ffd8799f581c420000029ad9527271b1b1e3c27ee065c18df70a4a4cfc3093a41a444341584fffffd8799f581c3c468b2a275a7df4b33625335232d4cfb45e651d289b2e073785618447457a43464f4e41ffa3457072696365d87b9fd8799f1b00102a3f18d9852f1b06f05b59d3b20000ffff47656e6444617465d905009f1b000003bb2cc3d418ff49737461727444617465d905009f1b00000092f3973818ffa0ff82583901bb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c613b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e4821a001e8480a1581c3c468b2a275a7df4b33625335232d4cfb45e651d289b2e0737856184a147457a43464f4e410182583901bb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c613b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e4821a00198ef8a1581c95a427e384527065f2f8946f5e86320d0117839a5e98ea2c0b55fb00a14448554e541a01040cc3825839018b0fac6777891b925d646af1727d1ef288338f7966455a93ce31dfbc3120b7074a8521bcc9ea2f05e38cf8924ffb7bc871ebfaa35ae98bf21a000f424082583901bb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c613b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e41a1d6593a1021a0004eec9031a0743ce5a075820411feee1738c31e1ac0e860abd4afd3c8288b6cd1abb051f21bff91a7a796f59081a0743cad609a1581c3c468b2a275a7df4b33625335232d4cfb45e651d289b2e0737856184a147457a43464f4e41020b5820041cf2ae5f43362e977280abbb0e9871c1c829a01bc59560d06d384b4d1bfc2c0d81825820b4bf6f7a29915cdf1aaac9d2112fc986bb3227d9cd04d7af418991cee23b07ed010e82581cbb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c61581c3b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e41082583901bb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c613b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e4821a03efae66b3581c078eafce5cd7edafdf63900edef2c1ea759e77f30ca81d6bbdeec924a14579756d6d691904f3581c115a3b670ea8b6b99d1c3d1d8041d7da9bd0b45532c24481cdbd9818a144746573741a000f4240581c1ddcb9c9de95361565392c5bdff64767492d61a96166cb16094e54bea1434f50541a02c5e3be581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa144534e454b191585581c29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6a1434d494e1a15b511cd581c32335fbb01744e526da8b9f97d759c2c07457c4c55eab98c372cdad6a14953505f494c7530634a02581c420000029ad9527271b1b1e3c27ee065c18df70a4a4cfc3093a41a44a14341584f1a133d12a2581c52162581184a457fad70470161179c5766f00237d4b67e0f1df1b4e6a1445452544c01581c562c0e6da43a062dde7d05b494d6b1a9d0d06a9d36131956c327b127a14953505f447a4a61657601581c5d16cc1a177b5d9ba9cfa9793b07e60f1fb70fea1f8aef064415d114a1434941471a018ece34581c826733e8e5d12c797f795be56b348982397e235d57074a992cb86b6ca14553544556451a0032b0bd581c8640914f83348a1b68d4b32205e2e4741455897e3e9edfe270d9069fa151576f6c6653796e6469636174653132343501581c8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaaa1444d494c4b01581c8fef2d34078659493ce161a6c7fba4b56afefa8535296a5743f69587a144414144411a0001e582581c95a427e384527065f2f8946f5e86320d0117839a5e98ea2c0b55fb00a14448554e541a0e6d983e581caf2e27f580f7f08e93190a81f72462f153026d06450924726645891ba144445249501a89e84f7a581cb3ad8b975d24235a43cb2a54d58c717ed9dd11560b4deba2273ffb1da1480014df104b5749431a3a06b367581cc0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d5073a14a57696e675269646572731a00470943581cdda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fba1480014df1047454e531a0047165c111a004c4b40a30380068159022659022301000032323232323232323232323232223232323232533300c3370e9000001099999199111980711299980a80089128008a99980919baf301630180010041300530180011300230170010012322230020033756602c0026ea4004dd7180900099199180511998011bab001232223002003374c002244a002464a66601e6ae8c0044894004488c00800ccc02894ccc03ccdd78009ba8480004894004488c00800c004004dd598091918091809180900098088021299980699807180780099111801001a4008264649319999806111299980a00089128008a9998089801180b800899111801001980b800899801801180b0009199119baf374e60300046e9cc06000530012bd8799fd8799f58205af098c47e6539e03dce07fb9cd83ba630bd901e6943db894c70f656a480fa5aff01ff00001001200116332300c22533301300114bd700998079801980b0009801180a8009180a180a8009bac30130051533300d3300e300f0013222300200332337029000000a40082930b0b0b180980118070009baa300f300e002300f300e001300e001223300422533300b00110051323330053011300f00223300933760601c602000600200420026004601a00200297adef6c602323002233002002001230022330020020015740ae6888cc0088cc0088cdc38010008a5013300124a0294494ccc00800448940044c94ccc00c0044c888c00800cdd69804180300109128009802000aab9f5573aae895d0918011baa0015573d0581840100d87980821a00014c221a01da9e55f5a21902a2a1636d7367816f44657868756e7465722054726164651902d1a178383363343638623261323735613764663462333336323533333532333264346366623435653635316432383962326530373337383536313834a167457a43464f4e41a664616c676fa3646c696e6b82784068747470733a2f2f6170702e61786f2e74726164652f636f6d706f7365722f61326634383739302d393432362d343361372d383134372d61656135313761386363663761646e616d656c536d617274204d61726b65746b6465736372697074696f6e60646e616d6577536d617274204d61726b6574203c4144412c2041584f3e657374726174a3646c696e6b782d68747470733a2f2f6170702e61786f2e74726164652f737472617465676965732f766965772f457a43464f4e41646e616d65606b6465736372697074696f6e60666173736574738260783e343230303030303239616439353237323731623162316533633237656530363563313864663730613461346366633330393361343161343434313538346667776562736974657168747470733a2f2f61786f2e7472616465696d656469615479706569696d6167652f706e67"
tx := Transaction.Transaction{}
decodedCbor, _ := hex.DecodeString(val)
err := cbor.Unmarshal(decodedCbor, &tx)
if err != nil {
t.Error(err)
}
recoded, err := cbor.Marshal(tx)
if err != nil {
t.Error(err)
}
if hex.EncodeToString(recoded) != val {
fmt.Println(val, hex.EncodeToString(recoded))
t.Error("Tx is not correct")
}

}
4 changes: 3 additions & 1 deletion plutusencoder/plutus.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,12 @@ func unmarshalPlutus(data *PlutusData.PlutusData, v interface{}, Plutusconstr ui
return fmt.Errorf("error: value is not a PlutusMap")
}
for idxStringHex, pAEl := range *values {
idxBytes, _ := hex.DecodeString(idxStringHex.String())
idxBytes, _ := hex.DecodeString(idxStringHex.HexString())
idx := string(idxBytes)
field, ok := tps.FieldByName(idx)
if !ok {
fmt.Println(idxBytes, idxStringHex.String(), idxStringHex)
fmt.Println(idx)
return fmt.Errorf("error: field %s does not exist", idx)
}
switch field.Type.String() {
Expand Down
3 changes: 2 additions & 1 deletion plutusencoder/plutusencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func TestMapInternal(t *testing.T) {
if err != nil {
t.Error(err)
}
if hex.EncodeToString(encoded) != "d87ba14158d87ba34556616c756500454279746573440102030449486578537472696e67581cfc11a9ef431f81b837736be5f53e4da29b9469c983d07f321262ce61" {
if hex.EncodeToString(encoded) != "d87ba14158d87ba345427974657344010203044556616c75650049486578537472696e67581cfc11a9ef431f81b837736be5f53e4da29b9469c983d07f321262ce61" {
t.Error("encoding error", hex.EncodeToString(encoded))
}

Expand Down Expand Up @@ -900,6 +900,7 @@ func TestMap(t *testing.T) {
resultinStruct := MapTest{}
err = plutusencoder.CborUnmarshal("d87ba74a496e64656641727261799fd87a9f05ffd87a9f05ffd87a9f05ffff434d6170d87ba14556616c7565054556616c756505454279746573440102030449486578537472696e67581cfc11a9ef431f81b837736be5f53e4da29b9469c983d07f321262ce614741646472657373d8799fd8799f581cbb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c61ffd8799fd8799fd8799f581c3b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e4ffffffff48446566417272617983d87b8105d87b8105d87b8105", &resultinStruct, 1)
if err != nil {
fmt.Println("FAILING HERE")
t.Error(err)
}
if resultinStruct.Address.String() != "addr1qxajla3qcrwckzkur8n0lt02rg2sepw3kgkstckmzrz4ccfm3j9pqrqkea3tns46e3qy2w42vl8dvvue8u45amzm3rjqvv2nxh" {
Expand Down
41 changes: 32 additions & 9 deletions serialization/Metadata/Metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ type PoliciesMetadata map[string]MinimalMetadata

type TagMetadata map[string]any

type Metadata map[int]TagMetadata
type Metadata map[int]any

type ShelleyMaryMetadata struct {
_ struct{} `cbor:",toarray,omitempty"`
Metadata Metadata `cbor:",omitempty"`
NativeScripts []NativeScript.NativeScript `cbor:",omitempty"`
}

/**
/*
*
MarshalCBOR marshals a ShelleyMaryMetadata instance into CBOR-encoded data.
Returns:
Expand Down Expand Up @@ -50,28 +52,45 @@ type AuxiliaryData struct {
_AlonzoMeta AlonzoMetadata
}

/**
/*
*
SetBasicMetadata sets the basic metadata for the AuxiliaryData.
*/
func (ad *AuxiliaryData) SetBasicMetadata(value Metadata) {
ad._basicMeta = value
}

/**
/*
*
SetAlonzoMetadata sets the Alonzo metadata for the AuxiliaryData.
*/
func (ad *AuxiliaryData) SetAlonzoMetadata(value AlonzoMetadata) {
ad._AlonzoMeta = value
}

/**
/*
*
SetShelleyMetadata sets the Shelley metadata for the AuxiliaryData.
*/
func (ad *AuxiliaryData) SetShelleyMetadata(value ShelleyMaryMetadata) {
ad._ShelleyMeta = value
if ad._ShelleyMeta.Metadata == nil {
ad._ShelleyMeta = value
} else {
currentMetadata := ad._ShelleyMeta.Metadata
for key, val := range value.Metadata {
currentMetadata[key] = val
}

}

}

/**
/*
*
Hash computes computes the has of the AuxiliaryData.
Returns:
Expand All @@ -90,7 +109,9 @@ func (ad *AuxiliaryData) Hash() []byte {
}
}

/**
/*
*
UnmarshalCBOR deserializes the AuxiliaryData from a CBOR-encoded byte slice.
Params:
Expand All @@ -110,7 +131,9 @@ func (ad *AuxiliaryData) UnmarshalCBOR(value []byte) error {
return nil
}

/**
/*
*
MarshalCBOR serializes the AUxiliaryData to a CBOR byte slice.
Returns:
Expand Down
Loading

0 comments on commit df0e5f2

Please sign in to comment.