package libkb

import (
	jsonw "github.com/keybase/go-jsonw"
)

func merkleRootFromString(raw string) (*MerkleRoot, error) {
	jw, err := jsonw.Unmarshal([]byte(raw))
	if err != nil {
		return nil, err
	}
	ret, err := NewMerkleRootFromJSON(jw, MerkleOpts{})
	if err != nil {
		return nil, err
	}
	return ret, nil
}

func merkleRootFromStringOrPanic(raw string) *MerkleRoot {
	root, err := merkleRootFromString(raw)
	if err != nil {
		panic(err)
	}
	return root
}

// Merkle Sequence #5323658, our current test merkle checkpoint
var prodCheckpoint5323658 = merkleRootFromStringOrPanic(
	`{"status":{"code":0,"name":"OK"},"hash":"84598ec296e526e7f299f425d72d487273892c14f385e828577d78cd740c013defe07cfb33cfd0c73271c9f77dae0ec78054314c2baa2e48900985bc575712d5","seqno":5323658,"ctime_string":"2019-05-07T18:39:10.000Z","ctime":1557254350,"payload_json":"{\"body\":{\"kbfs\":{\"private\":{\"root\":\"iKNlcGvEIH2J6deUCtelAZ682yv+zt/7UH5BmczbfonfrUpP1b19oWjEQFQ9kf0SCAKwVRW0MMYECfQq9mrmwlt3bPqonX0gKq87Yax4nkYlAwluIe+oL/eTTmsPYlmhVFzdIjWR0UxV/xajbm9uxBgLnx1jEzZknH7s3m3JbJFPcYJI741IE5WicHLEQMsO3W350HphuYbhCYThAyfe9XfKwwNCo1HgprVsrAG1kkyq+AE54mJdecjnDJKLFxJvfJCZsFp5h/puaIUXFT+ic27NZ1GhdAKidHPOXNHH4KF2AQ==\",\"version\":1},\"privateteam\":{\"root\":\"iKNlcGvEINojxeGAH+JJZo2IEBjsotElIa+scsmGKIEvPp5OPCk7oWjEQCWTxxZ7FlZWPxW39XOT1WnWGss4ybAKBmCR25XofMs08uwd2M9DQHaJh9Gno4Tp+8s8NVlUu84ohO4o08YNn4Gjbm9uxBj8l4GniZSP5Mh9/m1ZzrM3Gr1FvxFiXN+icHLEQJ+JU0cZj7R8hCp7K/aCydFMdvqCSbzmLocdDslR0blC14/47uf4MBDoK+o63ZapXLnXGmfmuxhY1HSZnrP8HqWic27NOxmhdAOidHPOXNHH4aF2AQ==\",\"version\":1},\"public\":{\"root\":\"hqFoxED55swUePDdjFmSa8c/lei2qwSq/WKjxV9wj+TbUmUmYDyxlYnPS2HMbctryl0OlJrlsmgo79DzkcIhdA4QJMy8onByxEDHa6+9XuvtNYjaVFMB0vyrnWytQE/+FlpasGVrUEQj50/r6Ab1HGzFz6NrB9g/a15DaBgvqA/1YcX9zZh2O9igonNuzWdjoXQBonRzzlzRx7mhdgE=\",\"version\":1}},\"key\":{\"fingerprint\":\"03e146cdaf8136680ad566912a32340cec8c9492\"},\"legacy_uid_root\":\"0c58a74abcb1db656146ebf667b5ea5cc55e208fbb534cd1b1e9454890358e5e\",\"prev\":\"132baf64b8a6ce5a165855200c36fafc36936085a8383852555168f42a2486ed75503d7c7d0634fc30a32f1b41d265ed727b1436b92bf33e89d67f5e0333db7c\",\"proof_services_hash\":\"c2ba2ac10ae88fd44620a5a911e3c9c060317423fb934c0563da96eb49b88caa1f9f03ac0952fbb1b45b80b375f399f34db0c5d82262ac2007e7c3c2090217d8\",\"pvl_hash\":\"bb64e9d94bea9e0e34e50bb020078bca8d4f8d22833ef877c052e98fe93ab0cd0946f16b7cbf551155a546aceda2b7131fd99e003c7258c0157b30879aa61b8b\",\"root\":\"84598ec296e526e7f299f425d72d487273892c14f385e828577d78cd740c013defe07cfb33cfd0c73271c9f77dae0ec78054314c2baa2e48900985bc575712d5\",\"seqno\":5323658,\"skips\":{\"1129354\":\"a4050d2c4adad6a3c1d8b5a9865db17099d288dcbc618022ea1a6780a23f227c\",\"3226506\":\"446f5752c4cf7f9378c7dbd596a9327499cfe559d168158e8720fdef176ebcf2\",\"4275082\":\"92e62fd26df550746e673f6a4cc5646e7771cd197c14a28e56a517ba5d85b613\",\"4799370\":\"341f3286918f5183b09b9307480720659709f659c771c6f436503f40997dcf75\",\"5061514\":\"20f01b509c345f7aeda5518f6a08a043eadf2050f17e336058db8ccf8f8ec928\",\"5192586\":\"4af89a99851461f0d761215e575c1b42815de31f978cf37576da0a2bf3557dbe\",\"5258122\":\"239bca2afe7e27034a11f9d7f4b5c2cded6857845f9b65f9dbea92f712240ba7\",\"5290890\":\"c0d7e22c9297c5ce3e0d8da2e6da2669c12d22d70f302f92c23586857a6fe4d9\",\"5307274\":\"6382e614e83579bf8cf851771faa82eeef6489e82a1a18997e40b804249f922c\",\"5315466\":\"204621960e887966fcc371ff0643f4de00c8098bf7b5b7b6fa3f4415870e9cc8\",\"5319562\":\"83ba107c78995c5851f565034b9791258335b84c53d8afd53b646c879ecf5063\",\"5321610\":\"14da36084f1edb912261e2d3463927fc6e41d048b09473cf8b276337f8e64541\",\"5322634\":\"07c7bc19a98d45f4b0c9d04176df4e9d481db01983df039aae405ce96bdd44b0\",\"5323146\":\"fdfc86be190c47d16d299d4317e95abd1ea6e09db0da6ebd33a624d15f6c0d3e\",\"5323402\":\"92b272094c55bbc4f5c07bf1981d2c96502fb4f1d7f8f0ff6640f035c6502586\",\"5323530\":\"ec237f22af0f6da778b495f89f2a40b66ee491509f71b1d562f3dc5cffbeee8c\",\"5323594\":\"52adc77439479e33220260c7f90011e16efef74c5ebf2f64ecbc619abf2549ad\",\"5323626\":\"203341629b8a220ca5960a1cc13053c20cb1edc4f9b91eec6f8be9ef431db05c\",\"5323642\":\"9a191f55c878878e1f3023603f1c6be960f2a61218bf992e863a8a0008e22bdd\",\"5323650\":\"44209b4a053af41c0825e14f1a31a05fc3680a98ba4297856fb17002ce9f1a69\",\"5323654\":\"db3d3fc66783edb25653dabb46a13504c346d058d5b58ac14ffd28017c9111b5\",\"5323656\":\"ce071810ff5b51fb3e5afc775f2c26b6ba131d525073361a6d5c1a8e9936daa7\",\"5323657\":\"cb9eba820ad2b38614a1c6b0626ac3c2e4d287b433ec5c88fb03a80b06661fb7\"},\"txid\":\"0894629d55e838f53dcb191a16d58315\",\"type\":\"merkle_root\"},\"ctime\":1557254350,\"tag\":\"signature\"}","txid":"0894629d55e838f53dcb191a16d58315","hash160":"a01e1f81868c2941096072fb26e4ab23b68346e0","payload_hash":"fcaedac1f83bd44afa9b536d119c7936a66c938029c29b7e93d49980029873b1","hash_meta":"fcaedac1f83bd44afa9b536d119c7936a66c938029c29b7e93d49980029873b1","sigs":{"010159baae6c7d43c66adf8fb7bb2b8b4cbe408c062cfc369e693ccb18f85631dbcd0a":{"sig":"-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v2\n\nkA0DAAgB9DgDo0namdUBy+tiAFzR0M57ImJvZHkiOnsia2JmcyI6eyJwcml2YXRl\nIjp7InJvb3QiOiJpS05sY0d2RUlIMko2ZGVVQ3RlbEFaNjgyeXYrenQvN1VINUJt\nY3piZm9uZnJVcFAxYjE5b1dqRVFGUTlrZjBTQ0FLd1ZSVzBNTVlFQ2ZRcTltcm13\nbHQzYlBxb25YMGdLcTg3WWF4NG5rWWxBd2x1SWUrb0wvZVRUbXNQWWxtaFZGemRJ\naldSMFV4Vi94YWpibTl1eEJnTG54MWpFelprbkg3czNtM0piSkZQY1lKSTc0MUlF\nNVdpY0hMRVFNc08zVzM1MEhwaHVZYmhDWVRoQXlmZTlYZkt3d05DbzFIZ3ByVnNy\nQUcxa2t5cStBRTU0bUpkZWNqbkRKS0xGeEp2ZkpDWnNGcDVoL3B1YUlVWEZUK2lj\nMjdOWjFHaGRBS2lkSFBPWE5ISDRLRjJBUT09IiwidmVyc2lvbiI6MX0sInByaXZh\ndGV0ZWFtIjp7InJvb3QiOiJpS05sY0d2RUlOb2p4ZUdBSCtKSlpvMklFQmpzb3RF\nbElhK3Njc21HS0lFdlBwNU9QQ2s3b1dqRVFDV1R4eFo3RmxaV1B4VzM5WE9UMVdu\nV0dzczR5YkFLQm1DUjI1WG9mTXMwOHV3ZDJNOURRSGFKaDlHbm80VHArOHM4TlZs\nVXU4NG9oTzRvMDhZTm40R2pibTl1eEJqOGw0R25pWlNQNU1oOS9tMVp6ck0zR3Ix\nRnZ4RmlYTitpY0hMRVFKK0pVMGNaajdSOGhDcD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6InNpZ25hdHVyZSJ9iQIcBAABCAAGBQJc\n0dDOAAoJEPQ4A6NJ2pnV8tEQAJ0EpKHcDfT5mT78WtJfuWVLlNqE9NrzK4F1lbQR\nMAoT/zaynP0dfB7q+HB5zYST6Rbwfj4ZEdI5OM6+hae+eosp/BMEE1TY+EbrpoJu\neRTPk2F5UWeGFVieVuL/sZcVBRPBSmzi/YW9ftTMrjesO/6jbIK13VoIy0a/ikJc\nZA4Rhb7HxOyM39stAGvCZ911owc+Rv8k0YoQAG2soH1zqHFyfI58RpHWH/MSUyDB\nyJsVf+S8C5T+52OL9cX8rpL6uRLqPFl3qlCT794eEQB0sVcOH4x+oZxXJ4+pmAvD\nF5xVTUzv34gJindLrda3s55DC6jzyXDbK+LEtZzcvt4u18s0x5SUHc69cl1qzecT\nJLEOTKKVzOuR8TYfXyUHgIdan7jQ2orAQ/GKo3udeVulL99uRSLdoFp9taWe0u8b\n/kWPIfHCkqvr69VKtYNAVHRyYz9w5oz/K6cGHHvg1B86QkQVYVgUVp/B5OWE8yUL\n9HBrX9GGHNRxzgVT/VI6dyb7T3R0i6w9BMxiy9PR3tAL3arMLqR65lx/sTRYBM6M\ny+vvmXYiOS31QWcdFB6RXYqTRKuzJ7GNNiyXVIJFY+JJAqvFJe4k9/7nhcjplDUq\nvVcul7p9TZIytQuc+YX8acJ2TMqR6UWInSfOri1Bz9VZRhGFPB9pVUZmpZppyjMq\nveHD\n=KDa4\n-----END PGP MESSAGE-----\n","fingerprint":"03E146CDAF8136680AD566912A32340CEC8C9492"},"01209ec31411b9b287f62630c2486005af27548ba62a59bbc802e656b888991a20230a":{"sig":" ","fingerprint":null}},"key_fingerprint":"03E146CDAF8136680AD566912A32340CEC8C9492"}`,
)

func GetMerkleCheckpoint(m MetaContext) *MerkleRoot {
	switch m.G().Env.GetRunMode() {
	case ProductionRunMode:
		return prodCheckpoint5323658
	default:
		return nil
	}
}
